event_system 0.1.1

Simple lightweight event system.
Documentation
  • Coverage
  • 0%
    0 out of 1 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 989.19 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 18s Average build duration of successful builds.
  • all releases: 18s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ramon54321/event_system
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ramon54321

Event System

Provides a simple lightweight event system for Rust.

Crate on Crates.io

Example

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
}