Skip to main content

Registry

Struct Registry 

Source
pub struct Registry<S> { /* private fields */ }
Expand description

Type-erased provider registry used for service discovery and DI-style lookup. Registration happens during bootstrap and runtime access is read-only via typed resolves. We keep the underlying maps behind RwLock<HashMap<..>> so registration stays simple while lookup only holds a short-lived read lock long enough to clone the stored Arc.

Implementations§

Source§

impl<S: 'static> Registry<S>

Source

pub fn new() -> Self

Create the service with an empty registry. You can register later.

Source

pub fn insert<C>(&self, item: Arc<C>) -> &Self
where C: Provider<S> + 'static,

Register a provider into the registry.

This accepts Arc<T> where T: Provider. The service is stored as a type-erased Arc<dyn Provider> but continues to point to the same underlying allocation (no new allocation is created).

If another service with the same concrete type is already registered, the new registration is skipped and a warning is logged.

Returns &Self to allow fluent chaining:

registry
    .insert(dns.clone())
    .insert(ipc.clone());
Source

pub fn with_typed<T, R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
where T: Provider<S> + 'static,

Execute a closure with a concrete typed reference &T if the service is registered.

Source

pub fn resolve<T>(&self) -> Option<Arc<T>>
where T: Provider<S> + 'static,

Resolve a concrete service as an owned Arc<T> handle.

This is the DI-style, high-level API: it returns a typed Arc<T> that points to the same underlying allocation as the internally registered provider (no new Arc allocation). The returned Arc is obtained by downcasting from a type-indexed map (TypeId).

Returns None if the type is not registered.

Source

pub fn providers(&self) -> Vec<Arc<dyn Provider<S>>>

Return a snapshot of registered providers.

Source

pub fn list_names(&self) -> Vec<&'static str>

Return the list of provider display names (for diagnostics only).

Source

pub fn lifecycle_names(&self) -> Result<Vec<&'static str>>

Return provider display names in lifecycle order.

This is useful for diagnostics and startup logging before running boot_all().

Source

pub fn run_all(&self, state: S, join_set: &mut JoinSet<Result<()>>) -> usize
where S: Clone + Send + 'static,

Spawn all runnable providers into the given JoinSet.

Returns the number of tasks spawned.

Source

pub fn validate_all(&self, state: &S) -> Result<()>

Run validate hook for all registered providers.

Source

pub async fn boot_all(&self, state: &S) -> Result<()>

Source

pub async fn shutdown_all(&self, state: &S) -> Result<()>

Source

pub async fn reload_one(&self, name: &str, state: &S) -> Result<()>

Source§

impl<S> Registry<S>
where S: ReloadState + 'static,

Source

pub async fn reload_all(&self, state: &S) -> Result<()>

Trait Implementations§

Source§

impl<S: 'static> Default for Registry<S>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S> !Freeze for Registry<S>

§

impl<S> RefUnwindSafe for Registry<S>

§

impl<S> Send for Registry<S>

§

impl<S> Sync for Registry<S>

§

impl<S> Unpin for Registry<S>

§

impl<S> UnsafeUnpin for Registry<S>

§

impl<S> UnwindSafe for Registry<S>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more