pub struct CompositionGraph<'a> { /* private fields */ }
Expand description
Represents a composition graph used to compose a new component from other components.
Implementations§
Source§impl<'a> CompositionGraph<'a>
impl<'a> CompositionGraph<'a>
Sourcepub fn add_component(&mut self, component: Component<'a>) -> Result<ComponentId>
pub fn add_component(&mut self, component: Component<'a>) -> Result<ComponentId>
Adds a new component to the graph.
The component name must be unique.
Sourcepub fn get_component(
&self,
id: impl Into<ComponentId>,
) -> Option<&Component<'a>>
pub fn get_component( &self, id: impl Into<ComponentId>, ) -> Option<&Component<'a>>
Gets a component from the graph.
Sourcepub fn get_component_by_name(
&self,
name: &str,
) -> Option<(ComponentId, &Component<'a>)>
pub fn get_component_by_name( &self, name: &str, ) -> Option<(ComponentId, &Component<'a>)>
Gets a component from the graph by name.
Sourcepub fn remove_component(&mut self, id: impl Into<ComponentId>)
pub fn remove_component(&mut self, id: impl Into<ComponentId>)
Removes a component from the graph.
All instances and connections relating to the component will also be removed.
Sourcepub fn instantiate(&mut self, id: impl Into<ComponentId>) -> Result<InstanceId>
pub fn instantiate(&mut self, id: impl Into<ComponentId>) -> Result<InstanceId>
Creates a new instance of a component in the composition graph.
Sourcepub fn get_component_of_instance(
&self,
id: impl Into<InstanceId>,
) -> Option<(ComponentId, &Component<'_>)>
pub fn get_component_of_instance( &self, id: impl Into<InstanceId>, ) -> Option<(ComponentId, &Component<'_>)>
Gets the component of the given instance.
Sourcepub fn remove_instance(&mut self, id: impl Into<InstanceId>)
pub fn remove_instance(&mut self, id: impl Into<InstanceId>)
Removes an instance from the graph.
All connections relating to the instance will also be removed.
Sourcepub fn connect(
&mut self,
source: impl Into<InstanceId> + Copy,
source_export: Option<impl Into<ExportIndex> + Copy>,
target: impl Into<InstanceId> + Copy,
target_import: impl Into<ImportIndex> + Copy,
) -> Result<()>
pub fn connect( &mut self, source: impl Into<InstanceId> + Copy, source_export: Option<impl Into<ExportIndex> + Copy>, target: impl Into<InstanceId> + Copy, target_import: impl Into<ImportIndex> + Copy, ) -> Result<()>
Creates a connection (edge) between instances in the composition graph.
A connection represents an instantiation argument.
If source_export
is None
, the source instance itself
is used as the instantiation argument.
Sourcepub fn disconnect(
&mut self,
source: impl Into<InstanceId>,
target: impl Into<InstanceId>,
target_import: impl Into<ImportIndex>,
) -> Result<()>
pub fn disconnect( &mut self, source: impl Into<InstanceId>, target: impl Into<InstanceId>, target_import: impl Into<ImportIndex>, ) -> Result<()>
Disconnects a previous connection between instances.
Requires that the source and target instances are valid.
If the source and target are not connected via the target’s import, then this is a no-op.
Sourcepub fn validate_connection(
&self,
source: impl Into<InstanceId>,
source_export: Option<impl Into<ExportIndex>>,
target: impl Into<InstanceId>,
target_import: impl Into<ImportIndex>,
) -> Result<()>
pub fn validate_connection( &self, source: impl Into<InstanceId>, source_export: Option<impl Into<ExportIndex>>, target: impl Into<InstanceId>, target_import: impl Into<ImportIndex>, ) -> Result<()>
Validates a connection between two instances in the graph.
Use None
for source_export
to signify that the instance
itself should be the source for the connection.
Returns Err(_)
if the connection would not be valid.