[][src]Macro revent::hub

macro_rules! hub {
    ($hub:ident { $($channel:ident: $type:ty),*$(,)? }) => { ... };
    ($hub:ident: $derives:ty $(,)? { $($channel:ident: $type:ty),*$(,)? }
     subscribe $structure:ident { $($subscription:ident),*$(,)? }) => { ... };
    ($hub:ident: $derives:ty, $($rest:ty),+ $(,)? { $($channel:ident: $type:ty),*$(,)? }
     subscribe $structure:ident { $($subscription:ident),*$(,)? }) => { ... };
    (selfscriber $structure:ident, $derivative:ty,) => { ... };
    (selfscriber $structure:ident, $derivative:ty, $($subscriptions:ident),*) => { ... };
}

Generate an event hub or a derivative and its associated boilerplate code.

use revent::hub;

pub trait MyTrait1 {}
pub trait MyTrait2 {}

hub! {
    MyHub {
        channel_name1: dyn MyTrait1,
        channel_name2: dyn MyTrait2,
    }
}

let mut my_hub = MyHub::default();
// or
let mut my_hub = MyHub::new();

my_hub.channel_name1.emit(|_| {
    // Do something with each subscriber of `channel_name1`.
});

The macro generates a struct of MyHub containing all topics. Topics are public members of the struct. See ExampleHub for an example of a generated hub.