pub struct ServiceRegistry { /* private fields */ }Expand description
Registry for unique services - one provider wins per service type.
Uses TypeId internally for type-safe lookup. Each service type can have
at most one registered provider; registering a new provider replaces the
existing one.
§Thread Safety
All operations are protected by RwLock, allowing concurrent reads with
exclusive writes.
§Example
ⓘ
use reovim_kernel::api::v1::{Service, ServiceRegistry};
use std::sync::Arc;
struct MyCompositor;
impl Service for MyCompositor {}
let registry = ServiceRegistry::new();
registry.register(Arc::new(MyCompositor));
let compositor = registry.get::<MyCompositor>();
assert!(compositor.is_some());Implementations§
Source§impl ServiceRegistry
impl ServiceRegistry
Sourcepub fn register<T: Service>(&self, service: Arc<T>)
pub fn register<T: Service>(&self, service: Arc<T>)
Register a unique service (replaces existing if any).
§Arguments
service- The service instance wrapped inArc
Sourcepub fn get<T: Service>(&self) -> Option<Arc<T>>
pub fn get<T: Service>(&self) -> Option<Arc<T>>
Get a unique service by type.
Returns None if no service of type T is registered.
Sourcepub fn get_required<T: Service>(&self, name: &str) -> Arc<T>
pub fn get_required<T: Service>(&self, name: &str) -> Arc<T>
Sourcepub fn get_or_create<R: Service + Default>(&self) -> Arc<R>
pub fn get_or_create<R: Service + Default>(&self) -> Arc<R>
Get or create a keyed service registry.
This is a convenience method for managing MultiServiceRegistry instances.
If a registry of type R doesn’t exist, creates and registers a new one.
§Type Parameters
R- TheMultiServiceRegistrytype (must implementService + Default)
Trait Implementations§
Source§impl Debug for ServiceRegistry
impl Debug for ServiceRegistry
Auto Trait Implementations§
impl !Freeze for ServiceRegistry
impl !RefUnwindSafe for ServiceRegistry
impl Send for ServiceRegistry
impl Sync for ServiceRegistry
impl Unpin for ServiceRegistry
impl UnsafeUnpin for ServiceRegistry
impl !UnwindSafe 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