Trait OnDispatcher

Source
pub trait OnDispatcher:
    Clone
    + Send
    + Sync
    + Unpin {
    // Required method
    fn on_dispatcher<R>(
        &self,
        f: impl FnOnce(Option<DispatcherRef<'_>>) -> R,
    ) -> R;

    // Provided methods
    fn on_maybe_dispatcher<R, E>(
        &self,
        f: impl FnOnce(DispatcherRef<'_>) -> Result<R, E>,
    ) -> Result<R, E>
       where E: From<Status> { ... }
    fn spawn_task(
        &self,
        future: impl Future<Output = ()> + Send + 'static,
    ) -> Result<(), Status>
       where Self: 'static { ... }
}
Expand description

A trait that can be used to access a lifetime-constrained dispatcher in a generic way.

Required Methods§

Source

fn on_dispatcher<R>(&self, f: impl FnOnce(Option<DispatcherRef<'_>>) -> R) -> R

Runs the function f with a lifetime-bound DispatcherRef for this object’s dispatcher. If the dispatcher is no longer valid, the callback will be given None.

Provided Methods§

Source

fn on_maybe_dispatcher<R, E>( &self, f: impl FnOnce(DispatcherRef<'_>) -> Result<R, E>, ) -> Result<R, E>
where E: From<Status>,

Helper version of OnDispatcher::on_dispatcher that translates an invalidated dispatcher handle into a [Status::BAD_STATE] error instead of giving the callback None.

Source

fn spawn_task( &self, future: impl Future<Output = ()> + Send + 'static, ) -> Result<(), Status>
where Self: 'static,

Spawn an asynchronous task on this dispatcher. If this returns Ok then the task has successfully been scheduled and will run or be cancelled and dropped when the dispatcher shuts down.

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 OnDispatcher for Arc<Dispatcher>

Source§

fn on_dispatcher<R>(&self, f: impl FnOnce(Option<DispatcherRef<'_>>) -> R) -> R

Source§

impl OnDispatcher for Weak<Dispatcher>

Source§

fn on_dispatcher<R>(&self, f: impl FnOnce(Option<DispatcherRef<'_>>) -> R) -> R

Source§

impl<'a, D> OnDispatcher for &'a D
where D: OnDispatcher,

Source§

fn on_dispatcher<R>(&self, f: impl FnOnce(Option<DispatcherRef<'_>>) -> R) -> R

Implementors§