[−][src]Crate eventd
This crate provides implementation of observer design pattern.
Events are strongly typed, with immediate dispatch and support subscription and unsubscription of multiple handlers.
Events are defined using event!
macro. It allows user to fully control lifetime, mutability
and thread safety constraints for event handlers.
Syntax
ⓘThis example is not tested
event!( /// Optional doc comments EventName[<'lifetime>] => [Fn|FnMut]([arg_name: ArgType, ...]) [+ Send + Sync + 'lifetime] );
Event arguments must be Clone
able types.
Examples
use eventd::event; // Event handlers are static immutable and not thread-safe event!(Event1 => Fn(x: u32) + 'static); // Event handlers are with lifetime `'a` mutable and not thread-safe event!(Event2<'a> => FnMut(y: u32) + 'a); // Event handlers are static, thread-safe and immutable event!(Event3 => Fn(z: u32) + Send + Sync + 'static);
Example usage
#[macro_use] extern crate eventd; event!(MyEvent => Fn(x: u8) + 'static); fn main() { let mut my_event = MyEvent::default(); let _ = my_event.subscribe(|x| println!("Got {}", x)); my_event.emit(42); }
Modules
example | Module with sample event. |
Macros
event | Macro used for defining event dispatcher types. |
Structs
Subscription | Token used to differentiate subscribers. |
SubscriptionMissing | Error emmited on attempt to unsubscribe with invalid subscription. |