singleton_registry/
lib.rs

1//! # Singleton Registry
2//!
3//! A thread-safe dependency injection registry for storing and retrieving global instances.
4//! Currently designed for write-once, read-many pattern.
5//!
6//! This crate provides a type-safe way to register and retrieve instances of any type
7//! that implements `Send + Sync + 'static`.
8//!
9//! ## Quick Start
10//!
11//! ```rust
12//! use singleton_registry::{register, get};
13//! use std::sync::Arc;
14//!
15//! // Register a value
16//! register("Hello, World!".to_string());
17//!
18//! // Retrieve the value
19//! let message: Arc<String> = get().unwrap();
20//! assert_eq!(&*message, "Hello, World!");
21//! ```
22//!
23//! ## Features
24//!
25//! - **Thread-safe**: All operations are safe to use across multiple threads
26//! - **Type-safe**: Values are stored and retrieved with full type information
27//! - **Zero-cost abstractions**: Minimal runtime overhead
28//! - **Tracing support**: Optional callback system for monitoring registry operations
29//!
30//! ## Main Functions
31//!
32//! - [`register`] - Register a value in the global registry
33//! - [`register_arc`] - Register an Arc-wrapped value (more efficient if you already have an Arc)
34//! - [`get`] - Retrieve a value as Arc<T>
35//! - [`get_cloned`] - Retrieve a cloned value (requires Clone)
36//! - [`contains`] - Check if a type is registered
37//! - [`set_trace_callback`] - Set up tracing for registry operations
38
39mod registry;
40
41// Re-export the main public API
42pub use registry::{
43    clear_trace_callback, contains, get, get_cloned, register, register_arc, set_trace_callback,
44    RegistryEvent, TraceCallback,
45};