iced_futures/
executor.rs

1//! Choose your preferred executor to power a runtime.
2use crate::MaybeSend;
3
4use futures::Future;
5
6/// A type that can run futures.
7pub trait Executor: Sized {
8    /// Creates a new [`Executor`].
9    fn new() -> Result<Self, futures::io::Error>
10    where
11        Self: Sized;
12
13    /// Spawns a future in the [`Executor`].
14    fn spawn(&self, future: impl Future<Output = ()> + MaybeSend + 'static);
15
16    /// Runs the given closure inside the [`Executor`].
17    ///
18    /// Some executors, like `tokio`, require some global state to be in place
19    /// before creating futures. This method can be leveraged to set up this
20    /// global state, call a function, restore the state, and obtain the result
21    /// of the call.
22    fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
23        f()
24    }
25}