eventsys

Crates.ioeventsys
lib.rseventsys
version0.1.1
sourcesrc
created_at2024-03-21 23:25:33.122925
updated_at2024-05-13 22:40:56.52828
descriptionA library for dispatching and processing events. Events can be handled in a deferred and/or immediate way.
homepage
repositoryhttps://github.com/wutterfly/eventsys
max_upload_size
id1182135
size72,616
(wutterfly)

documentation

README

EventSys

Rust

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:

  • handled with an event listener: EventBackend::register_listener()
  • be registered: EventBackend::register_store()

To trigger a new event, call EventBackend::new_event().

Using an EventBackend

Using an EventBackend should generally be done in 2 phases:

  • Create an new EventBackend and register all events
  • Use the EventBackend to trigger new events

Events can be triggered without needing mutable access to the EventBackend, while registering new event types does need mutable access.

Example

Example Listeners

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);

Example Batching

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
}

Licence

This project is licensed under the MIT license.

Commit count: 3

cargo fmt