12 stable releases

1.3.2 Feb 6, 2022
1.3.1 Feb 5, 2022
1.1.6 Jan 30, 2022
0.1.0 Jan 24, 2022

#27 in #event-bus

MIT license

12KB
187 lines

Eventbus-rs

This crate provides event bus for Rust

Example:

use eventbus_rs::{UnMutSubscriber, EventBus};
use async_trait::async_trait;
use std::any::Any;
// Create new topic
type Topic = ();

// Impl our subscriber
struct SimpleSubscriber;
#[async_trait]
impl UnMutSubscriber for SimpleSubscriber {
    async fn handle(&self, message: &(dyn Any + Send + Sync)) {}
}
async fn subscribe_and_publish() {
    // Create event bus
    let mut event_bus = EventBus::new().await;
    // Subscribe on our topic
    event_bus.subscribe_unmut::<Topic>(Box::new(SimpleSubscriber {})).await;
    // Publish event
    event_bus.publish_unmut::<Topic>(&"Hello".to_string()).await;
}

Dependencies

~0.9–1.6MB
~32K SLoC