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

#5 in #delegates

Download history 3/week @ 2024-02-19 4/week @ 2024-02-26 105/week @ 2024-04-01

105 downloads per month

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

~45KB