eventbus-rs

Crates.ioeventbus-rs
lib.rseventbus-rs
version1.3.2
sourcesrc
created_at2022-01-24 06:28:45.410044
updated_at2022-02-06 11:04:04.283018
descriptionEvent bus for rust
homepage
repositoryhttps://github.com/AlexSherbinin/eventbus-rs
max_upload_size
id520051
size11,142
Alex (AlexSherbinin)

documentation

README

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;
}
Commit count: 0

cargo fmt