Skip to main content

MultiServiceRegistry

Struct MultiServiceRegistry 

Source
pub struct MultiServiceRegistry<K: ServiceKey, T: ?Sized> { /* private fields */ }
Expand description

Registry for keyed services - multiple providers with typed key-based lookup.

Generic mechanism in kernel, typed keys defined in drivers.

§Type Safety

Uses K: ServiceKey bound to ensure only proper service keys can be used. The ServiceKey trait provides:

  • Compile-time enforcement (arbitrary types rejected)
  • Built-in service name for error messages
  • Self-documenting API

§Example

use reovim_kernel::api::v1::{MultiServiceRegistry, ServiceKey};

// In driver: define typed key implementing ServiceKey
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum VfsScheme { File, Memory, Ssh }

impl ServiceKey for VfsScheme {
    fn service_name() -> &'static str { "VFS" }
}

// In driver: define type alias with typed key
pub type VfsProviderRegistry = MultiServiceRegistry<VfsScheme, dyn VfsDriver>;

// Usage
let registry = VfsProviderRegistry::new();
registry.register(VfsScheme::File, Arc::new(local_fs_provider));
let provider = registry.get(&VfsScheme::File);

Implementations§

Source§

impl<K: ServiceKey, T: ?Sized + Send + Sync + 'static> MultiServiceRegistry<K, T>

Source

pub fn new() -> Self

Create a new empty keyed service registry.

Source

pub fn register(&self, key: K, provider: Arc<T>)

Register a provider for a typed key.

Replaces any existing provider for the same key.

§Arguments
  • key - The typed service key
  • provider - The provider instance wrapped in Arc
Source

pub fn get(&self, key: &K) -> Option<Arc<T>>

Get provider by typed key.

Returns None if no provider is registered for the key.

Source

pub fn get_required(&self, key: &K) -> Arc<T>
where K: Debug,

Get required provider or panic.

Uses K::service_name() for the error message automatically.

§Panics

Panics with FATAL: No {service_name} provider for {key:?} if not found.

Source

pub fn keys(&self) -> Vec<K>

List all registered keys.

Source

pub fn values(&self) -> Vec<Arc<T>>

List all registered providers.

Source

pub fn contains(&self, key: &K) -> bool

Check if a provider is registered for the given key.

Source

pub fn len(&self) -> usize

Get the number of registered providers.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Trait Implementations§

Source§

impl<K: ServiceKey + Debug, T: ?Sized + Send + Sync + 'static> Debug for MultiServiceRegistry<K, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: ServiceKey, T: ?Sized + Send + Sync + 'static> Default for MultiServiceRegistry<K, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: ServiceKey, T: ?Sized + Send + Sync + 'static> Service for MultiServiceRegistry<K, T>

Auto Trait Implementations§

§

impl<K, T> !Freeze for MultiServiceRegistry<K, T>

§

impl<K, T> !RefUnwindSafe for MultiServiceRegistry<K, T>

§

impl<K, T> Send for MultiServiceRegistry<K, T>
where T: Sync + Send + ?Sized,

§

impl<K, T> Sync for MultiServiceRegistry<K, T>
where T: Sync + Send + ?Sized,

§

impl<K, T> Unpin for MultiServiceRegistry<K, T>
where K: Unpin, T: ?Sized,

§

impl<K, T> UnsafeUnpin for MultiServiceRegistry<K, T>
where T: ?Sized,

§

impl<K, T> UnwindSafe for MultiServiceRegistry<K, T>
where K: UnwindSafe, T: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.