| Crates.io | dropslot |
| lib.rs | dropslot |
| version | 0.2.0 |
| created_at | 2025-07-10 09:05:12.631594+00 |
| updated_at | 2025-07-10 18:26:44.734867+00 |
| description | A high-performance publish-subscribe library with latest-only delivery semantics |
| homepage | https://github.com/ViezeVingertjes/dropslot |
| repository | https://github.com/ViezeVingertjes/dropslot |
| max_upload_size | |
| id | 1746060 |
| size | 189,810 |
A high-performance publish-subscribe library with latest-only delivery semantics for Rust. Built on top of Tokio with zero-copy operations and optimized for both high throughput and low latency scenarios.
bytes::Bytes and other efficient data typesasync and non-blocking synchronous operationsAdd dropslot to your Cargo.toml:
[dependencies]
dropslot = "0.2"
use dropslot::prelude::*;
use bytes::Bytes;
#[tokio::main]
async fn main() {
let bus = Bus::<Bytes>::new();
// Create a topic and subscriber
let topic = bus.topic("events");
let mut subscriber = topic.subscribe();
// Publish messages
topic.publish(Bytes::from("Hello, World!"));
// Receive the latest message
if let Some(message) = subscriber.wait_for_message().await {
println!("Received: {:?}", message);
}
}
use dropslot::prelude::*;
use bytes::Bytes;
// High throughput: optimized for many topics (large capacity)
let ht_bus = Bus::<Bytes>::with_capacity(64);
// Low latency: optimized for few topics (small capacity)
let ll_bus = Bus::<Bytes>::with_capacity(8);
// Custom capacity
let custom_bus = Bus::<Bytes>::with_capacity(128);
DropSlot is designed for high-performance scenarios and delivers exceptional performance:
| Operation | Latency | Throughput | Notes |
|---|---|---|---|
| Topic Creation | ~136 ns | ~7.4M ops/sec | Ultra-fast topic instantiation |
| Message Publishing | ~467 ns | ~2.1M ops/sec | Direct publish to topic |
| Subscriber Creation | ~510 ns | ~2.0M ops/sec | Fast subscriber setup |
| Message Retrieval | ~477 ns | ~2.1M ops/sec | Non-blocking message access |
| Topic Lookup | ~40 ns | ~25M ops/sec | Optimized topic resolution |
| Error Handling | ~330 ps | ~3.0B ops/sec | Near-zero overhead |
| Scenario | Performance | Details |
|---|---|---|
| 10 Topics | ~3.6 ฮผs | Excellent small-scale performance |
| 100 Topics | ~43 ฮผs | Linear scaling maintained |
| 1000 Topics | ~458 ฮผs | Consistent performance at scale |
| High Frequency | ~11 ฮผs/batch | 1000 message batches |
| Concurrent (16 threads) | ~3.3 ms | Excellent multi-threaded performance |
bytes::Bytes handlingDashMapAHashArc and weak referencesBenchmarks run on CI environment with optimized builds. Your mileage may vary based on hardware and workload.
use dropslot::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Event {
id: u64,
data: String,
}
let bus = Bus::<Event>::new();
let topic = bus.topic("events");
let event = Event {
id: 1,
data: "Hello".to_string(),
};
topic.publish(event);
use dropslot::prelude::*;
let bus = Bus::<String>::new();
let topic = bus.topic("events");
let mut subscriber = topic.subscribe();
match subscriber.try_get_message() {
Ok(Some(msg)) => println!("Received: {}", msg),
Ok(None) => println!("No new message"),
Err(e) if e.is_empty() => println!("No message available"),
Err(e) if e.is_disconnected() => println!("Topic disconnected"),
Err(e) => println!("Error: {}", e),
}
use dropslot::prelude::*;
let bus = Bus::<String>::new();
let topic = bus.topic("notifications");
// Multiple subscribers to the same topic
let mut email_sub = topic.subscribe();
let mut sms_sub = topic.subscribe();
let mut push_sub = topic.subscribe();
// All subscribers receive the same (latest) message
topic.publish("Important update!".to_string());
use dropslot::prelude::*;
let bus = Bus::<String>::new();
// Check topic count
println!("Active topics: {}", bus.topic_count());
// Get all topic names
let names = bus.topic_names();
println!("Topics: {:?}", names);
// Manually clean up unused topics (no automatic cleanup)
let removed = bus.cleanup_unused_topics();
println!("Removed {} unused topics", removed);
DropSlot is perfect for:
Bus<T>: Main message broker managing topicsTopic<T>: Individual message topics with publishers and subscribersSub<T>: Subscriber receiving messages from topicsBusError: Unified error handlingtokio::sync::watch channelsArc and Weak referencesFor convenience, you can import all commonly used types with the prelude:
use dropslot::prelude::*; // Imports Bus, Topic, Sub, and BusError
bytes - Zero-copy operations for bytes::Bytesserde - Serialization support for complex message typesEnable features in your Cargo.toml:
[dependencies]
dropslot = { version = "0.2", features = ["serde"] }
Run benchmarks with:
cargo bench
Run tests with:
cargo test
Run examples:
cargo run --example basic_usage
cargo run --example high_performance
cargo run --example real_world --features="serde"
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under either of
at your option.
See CHANGELOG.md for recent changes.
Note: This library implements latest-only delivery semantics, meaning subscribers only receive the most recent message. Topic cleanup is manual via bus.cleanup_unused_topics() - call this periodically in long-running applications to prevent memory leaks. For all-message delivery, consider using tokio::sync::broadcast or similar alternatives.