| Crates.io | rs_events |
| lib.rs | rs_events |
| version | 0.1.0 |
| created_at | 2025-09-24 04:32:53.994967+00 |
| updated_at | 2025-09-24 04:32:53.994967+00 |
| description | A flexible and ergonomic event emission crate for Rust. Supports both std/threaded and no_std/alloc environments, with tagging, listener lifetimes, async/sync emission, and robust error handling. |
| homepage | https://github.com/GreenJ84/Rust_events_crate |
| repository | https://github.com/GreenJ84/Rust_events_crate |
| max_upload_size | |
| id | 1852495 |
| size | 179,519 |
rust_events is a highly flexible, ergonomic, and portable event emitter crate for Rust.
It supports both high-performance threaded applications and minimal no_std/alloc environments, making it suitable for everything from servers to embedded systems.
use rs_events::{EventEmitter, EventPayload};
use std::sync::Arc;
fn main() {
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();
}
threaded (default): Uses std, tokio, and dashmap for high concurrency and async support.no_std/alloc: Minimal, dependency-free build for embedded and constrained environments.tokio for efficient scheduling.dashmap for lock-free, highly concurrent event storage in threaded mode (enabled by the threaded feature). This allows multiple threads to add, remove, and emit events without blocking, making it ideal for servers and async applications.BTreeMap for event storage. BTreeMap is chosen for its minimal dependency footprint and efficient ordered storage, suitable for embedded and constrained environments where concurrency is not available.--no-default-features for no_std/alloc.Add to your Cargo.toml:
[dependencies]
rust_events = "1.0.0"
Build with:
cargo build
Example:
use rust_events::{EventEmitter, EventPayload};
use std::sync::Arc;
fn main() {
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();
}
Build with:
cargo build --no-default-features
Use alloc::sync::Arc and alloc::string::String in your code. See crate docs for details.
Example:
extern crate alloc;
use alloc::sync::Arc;
use alloc::string::String;
use rust_events::{EventEmitter, EventPayload};
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();
let mut emitter = EventEmitter::<u32>::default();
let listener = emitter.add_limited("count", Some("tag1".to_string()), Arc::new(|payload| {
println!("Count: {}", payload.as_ref());
}), 5).unwrap();
assert_eq!(listener.tag(), Some(&"tag1".to_string()));
assert_eq!(listener.lifetime(), Some(5));
#[tokio::main]
async fn main() {
let mut emitter = EventEmitter::<String>::default();
emitter.add("event", None, Arc::new(|payload| {
println!("Received: {}", payload.as_ref());
})).unwrap();
// Blocking mode
emitter.emit_async("event", Arc::new("Hello Async".to_string()), false).await.unwrap();
// Parallel mode
emitter.emit_async("event", Arc::new("Hello Async".to_string()), true).await.unwrap();
}
let mut emitter = EventEmitter::<String>::default();
let listener = emitter.add_once("event", Some("tag1".to_string()), Arc::new(|_| {})).unwrap();
emitter.remove_listener("event", &listener).unwrap();
let mut emitter = EventEmitter::<String>::default();
emitter.add("event", None, Arc::new(|_| {})).unwrap();
let falloff = emitter.emit_final("event", Arc::new("Final".to_string())).unwrap();
assert_eq!(falloff.len(), 1); // Listener removed after final emit
threaded (default): Enables std/threaded support and dependencies (tokio, dashmap, futures).--no-default-features for no_std/alloc.MIT OR Apache-2.0
We welcome contributions of all kinds—bug reports, feature requests, documentation improvements, and code enhancements. Please:
See CONTRIBUTING.md for full details on how to get started, code standards, and the review process.
Jesse Greenough