| Crates.io | event_bus_rs |
| lib.rs | event_bus_rs |
| version | 0.1.6 |
| created_at | 2025-11-28 13:53:06.447239+00 |
| updated_at | 2025-12-05 02:12:39.845772+00 |
| description | A runtime-agnostic, async, and thread-safe event bus for Rust. |
| homepage | https://github.com/JasterV/event_bus.rs |
| repository | https://github.com/JasterV/event_bus.rs |
| max_upload_size | |
| id | 1955331 |
| size | 48,149 |
A runtime-agnostic, async, and thread-safe event bus for Rust. Designed to be efficient, simple, and easy to use, allowing you to publish and subscribe to messages across threads and async tasks.
futures::StreamEventBus::subscribe and EventBus::publishThe EventBus is build on top of bounded channels, which means that each time a topic is created, we need to specify a capacity.
The default one is set to an arbitrary value which is available and documented in the docs.
To know more about how the bounded channels work, check async_broadcast
Add to your Cargo.toml:
[dependencies]
event_bus_rs = "0.1.0"
futures = "0.3"
use event_bus_rs::EventBus;
use futures::StreamExt;
#[tokio::main]
async fn main() {
let bus = EventBus::new_with_topic_capacity(50);
// Subscribe to a topic
let mut sub = bus.subscribe("my_topic");
// Spawn a subscriber task
tokio::spawn(async move {
while let Some(msg) = sub.next().await {
println!("Received: {}", String::from_utf8_lossy(&msg));
}
});
// Publish a message
bus.publish("my_topic", b"Hello, EventBus!").unwrap();
}
Notes:
&[u8]; encoding/decoding is the user's responsibility.EventBus::new() -> EventBus – create a new busEventBus::new_with_topic_capacity() -> EventBus - create a new but with a configure topic capacityEventBus::subscribe(&self, topic: &str) -> Subscription – subscribe to a topicEventBus::publish(&self, topic: &str, data: &[u8]) -> Result<(), PublishError> – publish a messageSubscription implements futures::Stream<Item = Arc<[u8]>>MIT OR Apache-2.0