iced

Trait Executor

Source
pub trait Executor: Sized {
    // Required methods
    fn new() -> Result<Self, Error>
       where Self: Sized;
    fn spawn(&self, future: impl Future<Output = ()> + MaybeSend + 'static);

    // Provided method
    fn enter<R>(&self, f: impl FnOnce() -> R) -> R { ... }
}
Expand description

A type that can run futures.

Required Methods§

Source

fn new() -> Result<Self, Error>
where Self: Sized,

Creates a new Executor.

Source

fn spawn(&self, future: impl Future<Output = ()> + MaybeSend + 'static)

Spawns a future in the Executor.

Provided Methods§

Source

fn enter<R>(&self, f: impl FnOnce() -> R) -> R

Runs the given closure inside the Executor.

Some executors, like tokio, require some global state to be in place before creating futures. This method can be leveraged to set up this global state, call a function, restore the state, and obtain the result of the call.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Executor for Runtime

Source§

fn new() -> Result<Runtime, Error>

Source§

fn spawn(&self, future: impl Future<Output = ()> + Send + 'static)

Source§

fn enter<R>(&self, f: impl FnOnce() -> R) -> R

Source§

impl Executor for ThreadPool

Source§

fn new() -> Result<ThreadPool, Error>

Source§

fn spawn(&self, future: impl Future<Output = ()> + Send + 'static)

Implementors§

Source§

impl Executor for iced_futures::backend::native::async_std::Executor

Source§

impl Executor for iced_futures::backend::native::smol::Executor

Source§

impl Executor for iced_futures::backend::null::Executor