DynAsyncAccepts

Trait DynAsyncAccepts 

Source
pub trait DynAsyncAccepts<Value> {
    // Required method
    fn accept_async_dyn<'a>(
        &'a self,
        value: Value,
    ) -> Pin<Box<dyn Future<Output = ()> + 'a>>
       where Value: 'a;
}
Expand description

Asynchronous acceptor that returns a boxed trait-object future.

This trait is automatically implemented for every AsyncAccepts type when the alloc feature is enabled. It is useful when the consumer needs to store heterogeneous async acceptors behind trait objects.

use accepts::{AsyncAccepts, DynAsyncAccepts};
use core::future::Future;

struct TaskRunner;

impl AsyncAccepts<String> for TaskRunner {
    fn accept_async<'a>(&'a self, task: String) -> impl Future<Output = ()> + 'a
    where
        String: 'a,
    {
        async move {
            println!("{}", task);
        }
    }
}

// DynAsyncAccepts is provided automatically when `alloc` is enabled.
let runner = TaskRunner;
let dyn_runner: &dyn DynAsyncAccepts<String> = &runner;

Required Methods§

Source

fn accept_async_dyn<'a>( &'a self, value: Value, ) -> Pin<Box<dyn Future<Output = ()> + 'a>>
where Value: 'a,

Implementors§

Source§

impl<T, Value> DynAsyncAccepts<Value> for T
where T: AsyncAccepts<Value> + ?Sized,