Expand description
§Singleton Registry
A thread-safe dependency injection registry for storing and retrieving global instances. Currently designed for write-once, read-many pattern.
This crate provides a type-safe way to register and retrieve instances of any type
that implements Send + Sync + 'static.
§Quick Start
use singleton_registry::{register, get};
use std::sync::Arc;
// Register a value
register("Hello, World!".to_string());
// Retrieve the value
let message: Arc<String> = get().unwrap();
assert_eq!(&*message, "Hello, World!");§Features
- Thread-safe: All operations are safe to use across multiple threads
- Type-safe: Values are stored and retrieved with full type information
- Zero-cost abstractions: Minimal runtime overhead
- Tracing support: Optional callback system for monitoring registry operations
§Main Functions
register- Register a value in the global registryregister_arc- Register an Arc-wrapped value (more efficient if you already have an Arc)get- Retrieve a value as Arcget_cloned- Retrieve a cloned value (requires Clone)contains- Check if a type is registeredset_trace_callback- Set up tracing for registry operations
Enums§
- Registry
Event - Events emitted by the dependency-injection registry.
Functions§
- clear_
trace_ callback - Clears the tracing callback (disables registry tracing).
- contains
- Checks if a value of type
Tis registered in the global registry. - get
- Retrieves a value of type
Tfrom the global registry. - get_
cloned - Retrieves a clone of the value stored in the registry for the given type.
- register
- Registers a value of type
Tin the global registry. - register_
arc - Registers an
Arc<T>in the global registry. - set_
trace_ callback - Sets a tracing callback that will be invoked on every registry interaction.
Type Aliases§
- Trace
Callback - Type alias for the user-supplied tracing callback.