#event #delegate #observer

eventd

Simple observer-like event dispatcher

6 releases

0.3.2 Apr 9, 2019
0.3.1 Mar 5, 2019
0.2.0 Mar 1, 2019
0.1.1 Feb 28, 2019

#6 in #observer

MIT license

9KB
145 lines

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

Dependencies

~24KB