#event-listener #nodejs #events #name

bin+lib rust_event_listener

NodeJS like Event Listener library for rust!

1 unstable release

0.1.0 Mar 10, 2022

#39 in #event-listener

GPL-2.0 license

12KB
164 lines

Rust Event Listener

Crates.io Version Documentation

NodeJS like Event Listener library for rust!

    //Create new emitter
    let mut emitter = EventListener::new();

    //Set max listeners
    emitter.set_max_listeners(10);

    //Add listener
    emitter.on("test", Box::new(|name, d| {
        println!("Emited: {} {:#?}", name, d);
    }));

    emitter.emit("test", 1);

Examples

You can find examples here


lib.rs:

rust_event_listener

NodeJS like Event Listener library for rust!

Usage

use rust_event_listener::EventListener;

fn main() {
   let mut emitter = EventListener::new();
   //Set max listeners
   emitter.set_max_listeners(10);

   //Add listener
   emitter.on("test",  Box::new(|name, d| {
       println!("Emited: {} {:#?}", name, d);
   }));
   emitter.emit("test", "1".to_string());
}

You can find more examples here

No runtime deps