pub struct ComponentFactory { /* private fields */ }Expand description
Generic factory for Component instances. Uses definitions from the ComponentDefinitionRegistry and scopes to create and store instances for reuse.
Implementations§
Source§impl ComponentFactory
impl ComponentFactory
Sourcepub fn new(
definition_registry: ComponentDefinitionRegistryPtr,
scope_factories: FxHashMap<String, ScopeFactoryPtr>,
) -> Self
pub fn new( definition_registry: ComponentDefinitionRegistryPtr, scope_factories: FxHashMap<String, ScopeFactoryPtr>, ) -> Self
Creates a new factory with given registry and scope factories. The factory map should include built-in SINGLETON and PROTOTYPE for maximum compatibility with components, since they are usually the most popular. This is not a hard requirement, but care needs to be taken to ensue no component uses them.
Trait Implementations§
Source§impl ComponentInstanceProvider for ComponentFactory
impl ComponentInstanceProvider for ComponentFactory
Source§fn primary_instance(
&mut self,
type_id: TypeId,
) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
fn primary_instance( &mut self, type_id: TypeId, ) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
Tries to return a primary instance of a given component. A primary component is either the
only one registered or one marked as primary.
Source§fn instances(
&mut self,
type_id: TypeId,
) -> Result<Vec<(ComponentInstanceAnyPtr, CastFunction)>, ComponentInstanceProviderError>
fn instances( &mut self, type_id: TypeId, ) -> Result<Vec<(ComponentInstanceAnyPtr, CastFunction)>, ComponentInstanceProviderError>
Tries to instantiate and return all registered components for given type, stopping on first
error. Be aware this might be an expensive operation if the number of registered components
is high.
Source§fn instance_by_name(
&mut self,
name: &str,
type_id: TypeId,
) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
fn instance_by_name( &mut self, name: &str, type_id: TypeId, ) -> Result<(ComponentInstanceAnyPtr, CastFunction), ComponentInstanceProviderError>
Tries to return an instance with the given name and type.
Auto Trait Implementations§
impl Freeze for ComponentFactory
impl !RefUnwindSafe for ComponentFactory
impl Send for ComponentFactory
impl Sync for ComponentFactory
impl Unpin for ComponentFactory
impl !UnwindSafe for ComponentFactory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<CIP> TypedComponentInstanceProvider for CIPwhere
CIP: ComponentInstanceProvider + ?Sized,
impl<CIP> TypedComponentInstanceProvider for CIPwhere
CIP: ComponentInstanceProvider + ?Sized,
Source§fn primary_instance_typed<T>(
&mut self,
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn primary_instance_typed<T>(
&mut self,
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::primary_instance.
Source§fn primary_instance_option<T>(
&mut self,
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn primary_instance_option<T>(
&mut self,
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
Tries to get an instance like TypedComponentInstanceProvider::primary_instance_typed does,
but returns
None on missing instance.Source§fn instances_typed<T>(
&mut self,
) -> Result<Vec<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instances_typed<T>(
&mut self,
) -> Result<Vec<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::instances.
Source§fn instance_by_name_typed<T>(
&mut self,
name: &str,
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instance_by_name_typed<T>(
&mut self,
name: &str,
) -> Result<Arc<T>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
Typesafe version of ComponentInstanceProvider::instance_by_name.
Source§fn instance_by_name_option<T>(
&mut self,
name: &str,
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
fn instance_by_name_option<T>(
&mut self,
name: &str,
) -> Result<Option<Arc<T>>, ComponentInstanceProviderError>where
T: Injectable + ?Sized,
Tries to get an instance like TypedComponentInstanceProvider::instance_by_name_typed does,
but returns
None on missing instance.