pub struct ServiceRegistry { /* private fields */ }Expand description
Typed map keyed by TypeId. Stores Arc<dyn Any + Send + Sync> per slot; clones on lookup (cheap — services are
Arc internally). Built at boot, read-only thereafter.
Look up with exactly the type you registered. The key is
TypeId::of::<T>() of the value passed to register,
so registering an Arc<X> stores it under Arc<X>, and a later
get::<X>() silently returns None. The convention for an
already-shared handle is a named alias (type XHandle = Arc<X>) used on
both sides — see BufferStoreHandle,
ModeRegistryHandle and the other
*Handle aliases in this crate.
§Examples
use std::sync::Arc;
use lattice_mode::ServiceRegistry;
struct Clock(u64);
type ClockHandle = Arc<Clock>;
let mut services = ServiceRegistry::new();
services.register::<ClockHandle>(Arc::new(Clock(42)));
// Same type on both sides: found (an `Arc<ClockHandle>`, i.e. two layers).
assert_eq!(services.get::<ClockHandle>().unwrap().0, 42);
// The TypeId pitfall: `Clock` was never registered, only `Arc<Clock>`.
assert!(services.get::<Clock>().is_none());Implementations§
Source§impl ServiceRegistry
impl ServiceRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
An empty registry. The host fills it at boot; tests build one with only the services the code under test reads.
Trait Implementations§
Source§impl Debug for ServiceRegistry
impl Debug for ServiceRegistry
Source§impl Default for ServiceRegistry
impl Default for ServiceRegistry
Source§fn default() -> ServiceRegistry
fn default() -> ServiceRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ServiceRegistry
impl !UnwindSafe for ServiceRegistry
impl Freeze for ServiceRegistry
impl Send for ServiceRegistry
impl Sync for ServiceRegistry
impl Unpin for ServiceRegistry
impl UnsafeUnpin for ServiceRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more