Trait Notifiable

Source
pub trait Notifiable<IN>: Sized + Actor {
    // Required method
    fn notify<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        input: IN,
        context: &'life1 Context<Self>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Notifiable is an extension trait for Actor that enables it to process notifications.

Note: Handler workflow guarantees that sent messages will be delivered in order.

§Examples

This example assumes that messages is used with rt-tokio feature enabled.

struct Ping;

#[async_trait]
impl Actor for Ping {}

#[async_trait]
impl Notifiable<u8> for Ping {
    async fn notify(&mut self, input: u8, context: &Context<Self>) {
        println!("Received number {}", input);
    }
}

#[tokio::main]
async fn main() {
   let mut addr = Ping.spawn();
   addr.notify(42).await.unwrap();
}

Required Methods§

Source

fn notify<'life0, 'life1, 'async_trait>( &'life0 mut self, input: IN, context: &'life1 Context<Self>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Processes notification.

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.

Implementors§