Skip to main content

Crate registry_io

Crate registry_io 

Source
Expand description

§registry-io

High-performance event and callback registry primitive for Rust.

registry-io provides a focused alternative to channel-based notification when several components need to react to the same in-process event with the lowest possible dispatch overhead. The hot path is lock-free, allocation-free, and panic-isolating.

§Design philosophy

  • Sync-first. The default registry runs handlers inline on the calling thread, with sub-microsecond dispatch overhead.
  • Lock-free reads. Multiple threads can fire SyncRegistry::notify concurrently without serialization.
  • Zero allocation on the hot path. notify walks an arc_swap::ArcSwap snapshot of Arc<dyn Fn> pointers and dispatches each one — no allocations along the no-panic path.
  • Panic isolation. A panic in one handler is caught and does not stop sibling handlers or propagate to the caller.
  • Priority ordering. Handlers may be registered with a priority value; higher priorities fire first, ties broken in registration order.
  • RAII unregistration. HandlerGuard cleans up automatically.

§Quick start

use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};
use registry_io::SyncRegistry;

let registry: SyncRegistry<u32> = SyncRegistry::new();
let counter = Arc::new(AtomicU32::new(0));

let sink = Arc::clone(&counter);
let id = registry.register(move |value| {
    sink.fetch_add(*value, Ordering::Relaxed);
});

registry.notify(&5);
registry.notify(&7);
assert_eq!(counter.load(Ordering::Relaxed), 12);

assert!(registry.unregister(id));

§Feature flags

  • std (default) — enables the standard library. Required for sync and async registries.
  • sync (default) — exposes SyncRegistry. Implies std.
  • async — reserved for a future release; exposes AsyncRegistry for async fn handlers. Implies std.
  • hybrid — activates both sync and async.

§Out of scope

registry-io is a local, in-process primitive. It is not a pub/sub broker, not a message bus, and not a replacement for channels when you need cross-process or cross-network delivery with backpressure. See the project README for a list of when not to use it.

§License

Dual-licensed under Apache-2.0 OR MIT.

Re-exports§

pub use sync::HandlerGuard;sync
pub use sync::SyncRegistry;sync
pub use async::AsyncHandlerGuard;async
pub use async::AsyncRegistry;async

Modules§

asyncasync
Asynchronous, lock-free event registry.
syncsync
Synchronous, lock-free event registry.

Structs§

HandlerId
Opaque identifier for a registered handler.
PanicInfosync or async
Information about a panic that occurred inside a handler.

Constants§

VERSION
Crate version string, populated by Cargo at build time.