Skip to content

zrkn/eventd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eventd

Rust implementation of observer design pattern. Dispatch is immediate and multicast. For delayed handling you can use shrev.

License: MIT Crates.io Documentation

More information about this crate can be found in the crate documentation.

Features

  • Strongly typed
  • Subscribe and unsubscribe of multiple handlers
  • Configurable lifetime, mutability and thread safety constraints for handlers

Usage

To use eventd, first add this to your Cargo.toml:

[dependencies]
eventd = "0.3"

Next, you can use event! macro to define your event signatures and use them:

#[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);
}