| Crates.io | pubsub-rs |
| lib.rs | pubsub-rs |
| version | 0.1.1 |
| created_at | 2025-01-24 03:45:26.073122+00 |
| updated_at | 2025-01-24 05:24:59.249153+00 |
| description | This crate provides a simple yet powerful publish-subscribe (pubsub) system that allows multiple subscribers to receive messages published to specific topics. It is designed to be thread-safe, async-friendly, memory-efficient, and supports clean shutdown. |
| homepage | |
| repository | https://github.com/alaingilbert/pubsub-rs |
| max_upload_size | |
| id | 1529003 |
| size | 21,639 |
A publish-subscribe system for Rust with async/await support.
This crate provides a simple yet powerful publish-subscribe (pubsub) system that allows multiple subscribers to receive messages published to specific topics. It is designed to be thread-safe, async-friendly, memory-efficient, and supports clean shutdown.
Arc and DashMap for concurrent access.async-channel.Add the following to your Cargo.toml:
[dependencies]
pubsub-rs = "0.1.0"
use pubsub::{Pubsub, PubsubError};
#[tokio::main]
async fn main() {
let pubsub = Pubsub::new();
// Subscribe to topics
let subscriber = pubsub.subscribe(vec!["topic1", "topic2"]).await;
// Publish messages
pubsub.publish("topic1", "Hello".to_owned()).await;
// Receive messages
let (topic, message) = subscriber.recv().await.unwrap();
assert_eq!(topic, "topic1");
assert_eq!(message, "Hello");
}
The main error type is PubsubError, which occurs when:
DashMap for concurrent topic storage.Arc for shared ownership.Weak references to prevent memory leaks.See the tests module for more comprehensive usage examples.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
async-channel for providing the async channels used in this crate.DashMap for providing the concurrent hash map used for topic storage.