Skip to main content

ProviderRegistry

Struct ProviderRegistry 

Source
pub struct ProviderRegistry<Spec>
where Spec: ServiceSpec + 'static,
{ /* private fields */ }
Expand description

Registry of providers for one service specification.

Provider descriptors are captured during registration. Provider ids and aliases are normalized into ProviderName values and indexed case-insensitively, so lookup does not depend on provider metadata changing after registration. Automatic selection order is cached during registration updates. Registries store providers behind shared trait objects, so registered providers and service specifications must be 'static.

Implementations§

Source§

impl<Spec> ProviderRegistry<Spec>
where Spec: ServiceSpec + 'static,

Source

pub fn new() -> Self

Creates an empty provider registry.

§Returns

Empty provider registry.

Source

pub fn len(&self) -> usize

Gets the number of registered providers.

§Returns

Provider count.

Source

pub fn is_empty(&self) -> bool

Tells whether this registry contains no providers.

§Returns

true when no providers are registered.

Source

pub fn register<P>(&mut self, provider: P) -> Result<(), ProviderRegistryError>
where P: ServiceProvider<Spec> + 'static,

Registers a provider owned by the registry.

§Parameters
  • provider: Provider to register.
§Errors

Returns ProviderRegistryError when the provider descriptor is invalid or when its id or aliases conflict with an existing provider.

Source

pub fn register_shared( &mut self, provider: Arc<dyn ServiceProvider<Spec>>, ) -> Result<(), ProviderRegistryError>

Registers a shared provider.

§Parameters
  • provider: Shared provider to register.
§Errors

Returns ProviderRegistryError when the provider descriptor is invalid or when its id or aliases conflict with an existing provider.

Source

pub fn provider_names(&self) -> Vec<&str>

Gets canonical provider ids in registration order.

§Returns

Registered provider ids.

Source

pub fn iter_provider_names(&self) -> impl Iterator<Item = &str> + '_

Iterates over canonical provider ids in registration order.

§Returns

Iterator over registered provider ids.

Source

pub fn provider_descriptors(&self) -> Vec<&ProviderDescriptor>

Gets captured provider descriptors in registration order.

§Returns

Provider descriptors captured during registration.

Source

pub fn iter_provider_descriptors( &self, ) -> impl Iterator<Item = &ProviderDescriptor> + '_

Iterates over captured provider descriptors in registration order.

§Returns

Iterator over provider descriptors captured during registration.

Source

pub fn find_provider(&self, name: &str) -> Option<&dyn ServiceProvider<Spec>>

Finds a provider by id or alias.

§Parameters
  • name: Provider id or alias. Names are normalized before lookup.
§Returns

Matching provider, or None when no provider matches or name is invalid.

Source

pub fn resolve_provider( &self, name: &str, ) -> Result<&dyn ServiceProvider<Spec>, ProviderRegistryError>

Resolves a provider by id or alias.

§Parameters
  • name: Provider id or alias. Names are normalized before lookup.
§Returns

Matching provider.

§Errors

Returns ProviderRegistryError::EmptyProviderName or ProviderRegistryError::InvalidProviderName when name is invalid, or ProviderRegistryError::UnknownProvider when no provider matches.

Source

pub fn create_box( &self, name: &str, config: &Spec::Config, ) -> Result<Box<Spec::Service>, ProviderRegistryError>

Creates a boxed service from one provider name.

§Parameters
  • name: Provider id or alias.
  • config: Configuration passed to the provider.
§Returns

Boxed service value created by the selected provider.

§Errors

Returns ProviderRegistryError::EmptyProviderName or ProviderRegistryError::InvalidProviderName when name is invalid, ProviderRegistryError::UnknownProvider when no provider matches, ProviderRegistryError::ProviderUnavailable when the provider is not available, or ProviderRegistryError::ProviderCreate when the provider factory fails.

Source

pub fn create_arc( &self, name: &str, config: &Spec::Config, ) -> Result<Arc<Spec::Service>, ProviderRegistryError>

Creates an atomically shared service from one provider name.

§Parameters
  • name: Provider id or alias.
  • config: Configuration passed to the provider.
§Returns

Atomically shared service value created by the selected provider.

§Errors

Returns ProviderRegistryError::EmptyProviderName or ProviderRegistryError::InvalidProviderName when name is invalid, ProviderRegistryError::UnknownProvider when no provider matches, ProviderRegistryError::ProviderUnavailable when the provider is not available, or ProviderRegistryError::ProviderCreate when the provider factory fails.

Source

pub fn create_rc( &self, name: &str, config: &Spec::Config, ) -> Result<Rc<Spec::Service>, ProviderRegistryError>

Creates a locally shared service from one provider name.

§Parameters
  • name: Provider id or alias.
  • config: Configuration passed to the provider.
§Returns

Locally shared service value created by the selected provider.

§Errors

Returns ProviderRegistryError::EmptyProviderName or ProviderRegistryError::InvalidProviderName when name is invalid, ProviderRegistryError::UnknownProvider when no provider matches, ProviderRegistryError::ProviderUnavailable when the provider is not available, or ProviderRegistryError::ProviderCreate when the provider factory fails.

Source

pub fn create_auto_box( &self, config: &Spec::Config, ) -> Result<Box<Spec::Service>, ProviderRegistryError>

Creates a boxed service using automatic provider selection.

§Parameters
  • config: Configuration passed to candidate providers.
§Returns

Boxed service created by the highest-priority usable provider.

§Errors

Returns ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when all automatic candidates fail.

Source

pub fn create_auto_arc( &self, config: &Spec::Config, ) -> Result<Arc<Spec::Service>, ProviderRegistryError>

Creates an atomically shared service using automatic provider selection.

§Parameters
  • config: Configuration passed to candidate providers.
§Returns

Atomically shared service created by the highest-priority usable provider.

§Errors

Returns ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when all automatic candidates fail.

Source

pub fn create_auto_rc( &self, config: &Spec::Config, ) -> Result<Rc<Spec::Service>, ProviderRegistryError>

Creates a locally shared service using automatic provider selection.

§Parameters
  • config: Configuration passed to candidate providers.
§Returns

Locally shared service created by the highest-priority usable provider.

§Errors

Returns ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when all automatic candidates fail.

Source

pub fn create_selected_box( &self, selection: &ProviderSelection, config: &Spec::Config, ) -> Result<Box<Spec::Service>, ProviderRegistryError>

Creates a boxed service from explicit provider selection.

Automatic selection tries all registered providers ordered by descending priority and then by provider id. Named selection tries the primary provider followed by fallbacks in order. Selection stops at the first provider that can create a service.

§Parameters
  • selection: Provider selection policy.
  • config: Configuration passed to candidate providers.
§Returns

Boxed service created by the first successful provider candidate.

§Errors

Returns ProviderRegistryError::DuplicateProviderCandidate when a named selection repeats a candidate name, ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when every candidate is unknown, unavailable, or fails during creation.

Source

pub fn create_selected_arc( &self, selection: &ProviderSelection, config: &Spec::Config, ) -> Result<Arc<Spec::Service>, ProviderRegistryError>

Creates an atomically shared service from explicit provider selection.

Automatic selection tries all registered providers ordered by descending priority and then by provider id. Named selection tries the primary provider followed by fallbacks in order. Selection stops at the first provider that can create a service.

§Parameters
  • selection: Provider selection policy.
  • config: Configuration passed to candidate providers.
§Returns

Atomically shared service created by the first successful provider candidate.

§Errors

Returns ProviderRegistryError::DuplicateProviderCandidate when a named selection repeats a candidate name, ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when every candidate is unknown, unavailable, or fails during creation.

Source

pub fn create_selected_rc( &self, selection: &ProviderSelection, config: &Spec::Config, ) -> Result<Rc<Spec::Service>, ProviderRegistryError>

Creates a locally shared service from explicit provider selection.

Automatic selection tries all registered providers ordered by descending priority and then by provider id. Named selection tries the primary provider followed by fallbacks in order. Selection stops at the first provider that can create a service.

§Parameters
  • selection: Provider selection policy.
  • config: Configuration passed to candidate providers.
§Returns

Locally shared service created by the first successful provider candidate.

§Errors

Returns ProviderRegistryError::DuplicateProviderCandidate when a named selection repeats a candidate name, ProviderRegistryError::EmptyRegistry when the registry has no providers, or ProviderRegistryError::NoAvailableProvider when every candidate is unknown, unavailable, or fails during creation.

Trait Implementations§

Source§

impl<Spec> Clone for ProviderRegistry<Spec>
where Spec: ServiceSpec + 'static,

Source§

fn clone(&self) -> Self

Clones the provider list while sharing provider instances.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Spec> Debug for ProviderRegistry<Spec>
where Spec: ServiceSpec + 'static + Debug,

Source§

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

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

impl<Spec> Default for ProviderRegistry<Spec>
where Spec: ServiceSpec + 'static,

Source§

fn default() -> Self

Creates an empty provider registry.

Auto Trait Implementations§

§

impl<Spec> Freeze for ProviderRegistry<Spec>

§

impl<Spec> !RefUnwindSafe for ProviderRegistry<Spec>

§

impl<Spec> Send for ProviderRegistry<Spec>

§

impl<Spec> Sync for ProviderRegistry<Spec>

§

impl<Spec> Unpin for ProviderRegistry<Spec>

§

impl<Spec> UnsafeUnpin for ProviderRegistry<Spec>

§

impl<Spec> !UnwindSafe for ProviderRegistry<Spec>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.