Crate rs_events

Crate rs_events 

Source
Expand description

§Rust Events Crate

This crate provides a flexible, modular event system for Rust applications.

  • Listener: Represents a struct that holds a tag (optional), callback, and lifetime (optional) which can be registered to an event.
  • EventEmitter: Manages event registration and emission.
  • EventHandler: Trait defining the event API.

By default, the crate uses the threaded (multi-threaded, async) implementation. All core types are exported from the threaded module.

§Usage Examples

Threaded (default)

use rs_events::{EventEmitter, EventPayload, EventHandler};
use std::sync::Arc;

let mut emitter = EventEmitter::<String>::default();
emitter.add("event", None, Arc::new(|payload| {
    println!("Received: {}", payload.as_ref());
})).unwrap();
emitter.emit("event", Arc::new("Hello World".to_string())).unwrap();

no_std/alloc Build with:

cargo build --no-default-features
extern crate alloc;
use alloc::sync::Arc;
use alloc::string::String;
use rs_events::{EventEmitter, EventPayload, EventHandler};

let mut emitter = EventEmitter::<String>::default();
emitter.add("event", None, Arc::new(|payload| {
    // Handle event
})).unwrap();
emitter.emit("event", Arc::new(String::from("Hello no_std!"))).unwrap();

Structs§

EventEmitterthreaded
An event emitter that manages listeners and event emissions for a given payload type.
Listenerthreaded
A handle for an event listener callback.

Enums§

EventError
Errors that can occur in the event system.

Traits§

EventHandlerthreaded
Defines the contract for event-driven types that manage listeners and emit events.

Type Aliases§

Callback
Type alias for a callback pointer.
EventPayload
Type alias for an event payload pointer.