Crates.io | eventroute |
lib.rs | eventroute |
version | 0.1.0 |
source | src |
created_at | 2022-07-28 21:13:29.39395 |
updated_at | 2022-07-28 21:13:29.39395 |
description | Type safe event dispatching with functional middleware |
homepage | https://github.com/nyxtom/eventroute |
repository | https://github.com/nyxtom/eventroute |
max_upload_size | |
id | 634674 |
size | 8,493 |
eventroute provides a type safe middleware routing using generics rather than a specific event name or identifier. Middleware can be directly passed into .on
while .emit
provides a simple mechanism for dispatching to callback middleware.
pub struct Test {
foo: i32,
}
pub struct Foo {
bar: i32,
}
#[test]
fn test_router() {
let mut router = eventroute::new();
router.on(|i: i32| {
println!("{}", i * 10);
});
router.on(|(a, b): (i32, i32)| {
println!("{}", a * b);
});
router.on(|test: Test| {
println!("test {}", test.foo);
});
router.on(|foo: Foo| {
println!("bar {}", foo.bar);
});
router.emit(3);
router.emit((2, 3));
router.emit(Foo { bar: 232 });
router.emit(Test { foo: 232 });
}