Expand description
§Global Registry
A thread-safe global type registration system for Rust that allows you to:
- Register types globally by their TypeId
- Associate metadata or factory functions with types
- Retrieve registered information at runtime
§Quick Start
use global_registry::{TypeRegistry, Registrable};
// Define a trait for your registered types
trait Handler: Send + Sync {
fn handle(&self, data: &str) -> String;
}
#[derive(Clone)]
struct EmailHandler;
impl Handler for EmailHandler {
fn handle(&self, data: &str) -> String {
format!("Email: {}", data)
}
}
// Register the type
global_registry::register!(EmailHandler, EmailHandler);
// Use the registry
let result = TypeRegistry::global().get_cloned::<EmailHandler>().unwrap().handle("test");
assert_eq!(result, "Email: test");Macros§
- get
- Macro to get an Arc reference to a registered type from the global registry
- get_
cloned - Macro to get a cloned copy of a registered type from the global registry
- register
- Macro to register a type with a value in the global registry
- register_
arc - Macro to register an Arc
value in the global registry Takes a raw value and wraps it in Arc::new() internally - register_
factory - Macro to register a type with a factory function
Structs§
- Factory
Registry - A registry specifically for factory functions
- Type
Registry - The main type registry that stores registered types and their associated data
Enums§
- Registry
Error - Error types for the registry
Traits§
- Registrable
- A trait for types that can be registered in the global registry
Type Aliases§
- Factory
- Type alias for a factory function