10 个版本
0.1.9 | 2020年4月4日 |
---|---|
0.1.8 | 2020年1月24日 |
0.1.3 | 2018年11月28日 |
#4 in #swisstable
每月 42 次下载
4KB
emitbrown
本项目是 RustyEmitter 的分支,并使用 hashbrown 替换了 std::collections::HashMap
。它还有一些小的 API 更改
用法
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);
}
依赖项
~1MB
~14K SLoC