Skip to main content

ignis_events/
lib.rs

1//! # ignis_events
2//!
3//! `ignis_events` crate provides utilities to manage events and callbacks.
4//!
5//! It allows users to listen for events and execute the registered callbacks when an event occurs.
6//!
7//! ## Example
8//! ```rust
9//! use ignis_events::Event;
10//!
11//! struct MyService {
12//!     on_something_happened: Event<u32>,
13//! }
14//!
15//! impl MyService {
16//!     fn new() -> Self {
17//!         Self {
18//!             on_something_happened: Event::<u32>::new(),
19//!         }
20//!     }
21//! }
22//!
23//! let service = MyService::new();
24//! let handle = service.on_something_happened.connect(|arg| {
25//!     println!("Something happened");
26//!     assert_eq!(*arg, 67);
27//! });
28//!
29//! // NOTE: usually you must not emit events by yourself.
30//! // It should be done by the struct owning the event.
31//! service.on_something_happened.emit(&67);
32//!
33//! // Disconnect when you do not need to invoke this callback anymore
34//! service.on_something_happened.disconnect(handle);
35//! ```
36#[warn(missing_docs)]
37mod event;
38
39pub use event::Event;