10 releases
0.1.9 | Apr 4, 2020 |
---|---|
0.1.8 | Jan 24, 2020 |
0.1.3 | Nov 28, 2018 |
#7 in #swisstable
4KB
emitbrown
This project is a fork of RustyEmitter and it uses hashbrown to replace std::collections::HashMap
.
It has also some small api changes
usage
extern crate emitbrown;
extern crate hashbrown;
use emitbrown::{Events, Emitter};
use hashbrown::HashMap;
fn main(){
let (mut emitter, callback) = (
// create a new emitter instance
Emitter::new(),
// creating the handler in the same lifetime
Box::new(|data:& mut HashMap<String, String>| {
println!("IT WORKS!");
for (key, value) in data {
println!("{}: {}", key, value);
}
}
));
// listen to the "IT WORKS" event
emitter.on("IT WORKS".to_string(), callback);
// fire the "IT WORKS" event with an empty HashMap;
emitter.emit("IT WORKS".to_string(), &mut HashMap::new());
// fire it again passing some more data
let mut data : HashMap<String, String> = HashMap::new();
data.insert("some data".to_string(), "here".to_string());
emitter.emit("IT WORKS".to_string(), &mut data);
}
Dependencies
~1MB
~13K SLoC