Crates.io | eventsys |
lib.rs | eventsys |
version | 0.1.1 |
source | src |
created_at | 2024-03-21 23:25:33.122925 |
updated_at | 2024-05-13 22:40:56.52828 |
description | A library for dispatching and processing events. Events can be handled in a deferred and/or immediate way. |
homepage | |
repository | https://github.com/wutterfly/eventsys |
max_upload_size | |
id | 1182135 |
size | 72,616 |
This is a work-in-progess project and not for production use.
A library for dispatching and processing events. Events can be handled in a deferred and/or immediate way.
Events can be:
EventBackend::register_listener()
EventBackend::register_store()
To trigger a new event, call EventBackend::new_event()
.
EventBackend
Using an EventBackend
should generally be done in 2 phases:
EventBackend
and register all eventsEventBackend
to trigger new eventsEvents can be triggered without needing mutable access to the EventBackend
,
while registering new event types does need mutable access.
use eventsys::EventBackend;
// create event system, events can be a max size of 16 bytes
let mut system = EventBackend::<16>::new();
// create listener to be called on event trigger
let listener = |event: &u32| {
// handle event
};
// register listener for event type
system.register_listener::<u32>(listener).unwrap();
// trigger event
system.new_event::<u32>(123);
use eventsys::{EventBackend, SlotType};
// create event system, events can be a max size of 16 bytes
let mut system = EventBackend::<16>::new();
// register listener for event type
system.register_store::<u32>(SlotType::All).unwrap();
// trigger event
system.new_event::<u32>(123);
system.new_event::<u32>(456);
system.new_event::<u32>(789);
// query batch
let event_iter = system.query::<u32>().unwrap();
for event in event_iter {
// handle event
}
This project is licensed under the MIT license.