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,
impl<Spec> ProviderRegistry<Spec>where
Spec: ServiceSpec + 'static,
Sourcepub fn register<P>(&mut self, provider: P) -> Result<(), ProviderRegistryError>where
P: ServiceProvider<Spec> + 'static,
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.
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.
Sourcepub fn provider_names(&self) -> Vec<&str>
pub fn provider_names(&self) -> Vec<&str>
Sourcepub fn iter_provider_names(&self) -> impl Iterator<Item = &str> + '_
pub fn iter_provider_names(&self) -> impl Iterator<Item = &str> + '_
Iterates over canonical provider ids in registration order.
§Returns
Iterator over registered provider ids.
Sourcepub fn provider_descriptors(&self) -> Vec<&ProviderDescriptor>
pub fn provider_descriptors(&self) -> Vec<&ProviderDescriptor>
Gets captured provider descriptors in registration order.
§Returns
Provider descriptors captured during registration.
Sourcepub fn iter_provider_descriptors(
&self,
) -> impl Iterator<Item = &ProviderDescriptor> + '_
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.
Sourcepub fn find_provider(&self, name: &str) -> Option<&dyn ServiceProvider<Spec>>
pub fn find_provider(&self, name: &str) -> Option<&dyn ServiceProvider<Spec>>
Sourcepub fn resolve_provider(
&self,
name: &str,
) -> Result<&dyn ServiceProvider<Spec>, ProviderRegistryError>
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.
Sourcepub fn create_box(
&self,
name: &str,
config: &Spec::Config,
) -> Result<Box<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_arc(
&self,
name: &str,
config: &Spec::Config,
) -> Result<Arc<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_rc(
&self,
name: &str,
config: &Spec::Config,
) -> Result<Rc<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_auto_box(
&self,
config: &Spec::Config,
) -> Result<Box<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_auto_arc(
&self,
config: &Spec::Config,
) -> Result<Arc<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_auto_rc(
&self,
config: &Spec::Config,
) -> Result<Rc<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_selected_box(
&self,
selection: &ProviderSelection,
config: &Spec::Config,
) -> Result<Box<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_selected_arc(
&self,
selection: &ProviderSelection,
config: &Spec::Config,
) -> Result<Arc<Spec::Service>, ProviderRegistryError>
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.
Sourcepub fn create_selected_rc(
&self,
selection: &ProviderSelection,
config: &Spec::Config,
) -> Result<Rc<Spec::Service>, ProviderRegistryError>
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.