3 releases

new 0.1.2 Jan 15, 2025
0.1.1 Jul 11, 2024
0.1.0 May 9, 2023

#45 in No standard library

Download history 235/week @ 2024-09-27 450/week @ 2024-10-04 1105/week @ 2024-10-11 999/week @ 2024-10-18 595/week @ 2024-10-25 144/week @ 2024-11-01 320/week @ 2024-11-08 446/week @ 2024-11-15 516/week @ 2024-11-22 410/week @ 2024-11-29 471/week @ 2024-12-06 342/week @ 2024-12-13 782/week @ 2024-12-20 692/week @ 2024-12-27 521/week @ 2025-01-03 474/week @ 2025-01-10

2,523 downloads per month

GPL-3.0-or-later OR Apache-2…

5KB
51 lines

handler_table

Crates.io Docs.rs CI

A lock-free table of event handlers.

Examples

use handler_table::HandlerTable;

static TABLE: HandlerTable<8> = HandlerTable::new();

TABLE.register_handler(0, || {
   println!("Hello, event 0!");
});
TABLE.register_handler(1, || {
   println!("Hello, event 1!");
});

assert!(TABLE.handle(0)); // print "Hello, event 0!"
assert!(!TABLE.handle(2)); // unregistered

assert!(TABLE.unregister_handler(2).is_none());
let func = TABLE.unregister_handler(1).unwrap(); // retrieve the handler
func(); // print "Hello, event 1!"

assert!(!TABLE.handle(1)); // unregistered

No runtime deps