pub trait ComponentDefinitionRegistry {
// Required methods
fn register_component(
&mut self,
target: TypeId,
target_name: &str,
metadata: &ComponentMetadata,
) -> Result<(), ComponentDefinitionRegistryError>;
fn register_alias(
&mut self,
alias_type: TypeId,
target_type: TypeId,
alias_name: &str,
target_name: &str,
metadata: &ComponentAliasMetadata,
) -> Result<(), ComponentDefinitionRegistryError>;
fn components_by_type(&self, type_id: TypeId) -> Vec<ComponentDefinition>;
fn component_by_name(
&self,
name: &str,
type_id: TypeId,
) -> Option<ComponentDefinition>;
fn primary_component(&self, type_id: TypeId) -> Option<ComponentDefinition>;
fn is_registered(&self, type_id: TypeId) -> bool;
fn is_name_registered(&self, name: &str) -> bool;
fn all_definitions(&self) -> FxHashMap<TypeId, Vec<ComponentDefinition>>;
}Expand description
A registry of component definitions which can be used when requesting instances via a ComponentInstanceProvider.
Required Methods§
Sourcefn register_component(
&mut self,
target: TypeId,
target_name: &str,
metadata: &ComponentMetadata,
) -> Result<(), ComponentDefinitionRegistryError>
fn register_component( &mut self, target: TypeId, target_name: &str, metadata: &ComponentMetadata, ) -> Result<(), ComponentDefinitionRegistryError>
Adds a new definition for a given type. Note: handling of duplicate component names is registry-dependent. Name is used for reporting purposes.
Sourcefn register_alias(
&mut self,
alias_type: TypeId,
target_type: TypeId,
alias_name: &str,
target_name: &str,
metadata: &ComponentAliasMetadata,
) -> Result<(), ComponentDefinitionRegistryError>
fn register_alias( &mut self, alias_type: TypeId, target_type: TypeId, alias_name: &str, target_name: &str, metadata: &ComponentAliasMetadata, ) -> Result<(), ComponentDefinitionRegistryError>
Adds an alias for a component of target type. This is useful when registering
dyn Trait as an alias for a given concrete type. If alias cannot by cast to target,
component creation will fail. Names are used for reporting purposes.
Sourcefn components_by_type(&self, type_id: TypeId) -> Vec<ComponentDefinition>
fn components_by_type(&self, type_id: TypeId) -> Vec<ComponentDefinition>
Returns all registered definitions for a given type.
Sourcefn component_by_name(
&self,
name: &str,
type_id: TypeId,
) -> Option<ComponentDefinition>
fn component_by_name( &self, name: &str, type_id: TypeId, ) -> Option<ComponentDefinition>
Returns a definition with given name.
Sourcefn primary_component(&self, type_id: TypeId) -> Option<ComponentDefinition>
fn primary_component(&self, type_id: TypeId) -> Option<ComponentDefinition>
Returns primary component for a given type.
Sourcefn is_registered(&self, type_id: TypeId) -> bool
fn is_registered(&self, type_id: TypeId) -> bool
Checks if given type is present in this registry.
Sourcefn is_name_registered(&self, name: &str) -> bool
fn is_name_registered(&self, name: &str) -> bool
Checks if there’s a definition with given name.
Sourcefn all_definitions(&self) -> FxHashMap<TypeId, Vec<ComponentDefinition>>
fn all_definitions(&self) -> FxHashMap<TypeId, Vec<ComponentDefinition>>
Returns a copy of the whole registry as a map.