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<P>(&self, item: Arc<P>) -> Result<&Self>
where P: Provider<S> + 'static,

Register a provider into the registry.

This accepts Arc<P> where P: 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, registration is rejected.

Returns &Self to allow fallible fluent chaining:

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

pub fn bind_dyn<I, P>( &self, cast: impl FnOnce(Arc<P>) -> Arc<I>, ) -> Result<&Self>
where I: ?Sized + Send + Sync + 'static, P: Provider<S> + 'static,

Bind a registered concrete provider as a trait-object capability.

This does not register a second lifecycle provider. It resolves the existing concrete provider P, casts the same Arc<P> into Arc<I>, and stores that trait-object handle under TypeId::of::<I>().

Returns an error if P has not been registered yet. If I already has a binding, the new binding replaces it.

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 resolve_dyn<I>(&self) -> Option<Arc<I>>
where I: ?Sized + Send + Sync + 'static,

Resolve a trait-object capability bound with bind_dyn.

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 validate_all(&self, state: &S) -> Result<ValidationOutcome>

Run validate for every provider in lifecycle order.

Lifecycle-plan failures remain outer errors. A provider validation failure does not prevent later providers from being checked; every provider failure is retained in the outcome.

Source

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

Source

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

Run Finalizable::finalize for every provider that exposes the capability, in reverse lifecycle order. Called by the bootstrap layer after the runnable tasks have drained. One failure does not stop later finalizers; every failure is retained in the outcome.

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<ReloadOutcome>

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>
where RwLock<HashMap<TypeId, Arc<dyn Provider<S>>>>: Send,

§

impl<S> Sync for Registry<S>
where RwLock<HashMap<TypeId, Arc<dyn Provider<S>>>>: Sync,

§

impl<S> Unpin for Registry<S>
where RwLock<HashMap<TypeId, Arc<dyn Provider<S>>>>: Unpin,

§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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