[][src]Trait lifeline::prelude::Message

pub trait Message<Bus>: Debug {
    type Channel: Channel;
}

Attaches a channel to the Bus, carrying Self as a message.

The Channel associated type should be the Sender of the channel which will carry this message.

Once implemented, the bus.rx::<Self>(), bus.tx::<Self>(), and bus.capacity::<Self>() methods can be called.

Example:

use lifeline::prelude::*;
use tokio::sync::mpsc;

lifeline_bus!(pub struct ExampleBus);

#[derive(Debug)]
pub struct ExampleMessage;

impl Message<ExampleBus> for ExampleMessage {
   type Channel = mpsc::Sender<Self>;
}

fn main() -> anyhow::Result<()> {
    let bus = ExampleBus::default();
    let mut tx = bus.tx::<ExampleMessage>()?;
    Ok(())
}

Associated Types

Loading content...

Implementors

Loading content...