Skip to main content

ServiceRegistry

Struct ServiceRegistry 

Source
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

Source

pub fn new() -> Self

Create a new empty service registry.

Source

pub fn register<T: Service>(&self, service: Arc<T>)

Register a unique service (replaces existing if any).

§Arguments
  • service - The service instance wrapped in Arc
Source

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.

Source

pub fn get_required<T: Service>(&self, name: &str) -> Arc<T>

Get required service or panic.

§Panics

Panics with FATAL: No provider for {name} if no service is registered.

§Arguments
  • name - Human-readable service name for the error message
Source

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 - The MultiServiceRegistry type (must implement Service + Default)

Trait Implementations§

Source§

impl Debug for ServiceRegistry

Source§

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

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

impl Default for ServiceRegistry

Source§

fn default() -> Self

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

Auto Trait Implementations§

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.