ComponentDefinitionRegistry

Trait ComponentDefinitionRegistry 

Source
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§

Source

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.

Source

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.

Source

fn components_by_type(&self, type_id: TypeId) -> Vec<ComponentDefinition>

Returns all registered definitions for a given type.

Source

fn component_by_name( &self, name: &str, type_id: TypeId, ) -> Option<ComponentDefinition>

Returns a definition with given name.

Source

fn primary_component(&self, type_id: TypeId) -> Option<ComponentDefinition>

Returns primary component for a given type.

Source

fn is_registered(&self, type_id: TypeId) -> bool

Checks if given type is present in this registry.

Source

fn is_name_registered(&self, name: &str) -> bool

Checks if there’s a definition with given name.

Source

fn all_definitions(&self) -> FxHashMap<TypeId, Vec<ComponentDefinition>>

Returns a copy of the whole registry as a map.

Implementors§