Struct event_emitter::Event [] [src]

pub struct Event<T> { /* fields omitted */ }

Single event emitter.

Contrary to the Node.js-like EventEmitter, this one isn't parametrized with the event type, because it, basically, represents the event itself.

Such design gives us more flexibility without sacrificing type safety. Events that are logically bound together can still be grouped into, e.g., a struct, but they don't have to share the same payload type.

Examples

#[derive(Default)]
struct Events {
    first: Event<&'static str>,
    second: Event<i32>,
}

let mut events = Events::default();

events.first.subscribe(|&data| {
    assert_eq!("data for a", data);
});

events.second.subscribe(|&data| {
    assert_eq!(42, data);
});

events.first.emit("data for a");
events.second.emit(42);

Methods

impl<T> Event<T>
[src]

[src]

Creates a new event with no handlers.

[src]

Registers an event handler. There may be more that one handler at a time.

[src]

Fires the event, passing the payload as an argument of each event handler.

Trait Implementations

impl<T> Default for Event<T>
[src]

[src]

Returns the "default value" for a type. Read more