Crates.io | event_system |
lib.rs | event_system |
version | 0.1.1 |
source | src |
created_at | 2022-12-02 12:12:47.231536 |
updated_at | 2022-12-02 12:17:00.809513 |
description | Simple lightweight event system. |
homepage | |
repository | https://github.com/ramon54321/event_system |
max_upload_size | |
id | 728347 |
size | 4,641 |
Provides a simple lightweight event system for Rust.
The first entry in the macro is the name of the event system struct.
Any following entries take the form of struct-enum variants, where the name is the event name and the data the structure for the payload when the event is fired.
use event_system::create_event_system;
create_event_system! {
EventSystem // <- Name of struct
ApplicationLoad {}
ApplicationExit {}
KeyDown {
key: u8,
}
}
fn main() {
let mut events = EventSystem::new();
events.register_key_down(key_down);
events.fire_application_load();
events.fire_key_down(EventKeyDown { key: 55 });
events.fire_application_exit();
}
fn key_down(packet: EventKeyDown) -> bool {
println!("Key down {:?}", packet.key);
true
}