pub trait Container {
// Required methods
fn container_node(&self) -> Node;
fn hugr_mut(&mut self) -> &mut Hugr;
fn hugr(&self) -> &Hugr;
// Provided methods
fn add_child_node(&mut self, node: impl Into<OpType>) -> Node { ... }
fn add_other_wire(&mut self, src: Node, dst: Node) -> Wire { ... }
fn add_constant(&mut self, constant: impl Into<Const>) -> ConstID { ... }
fn define_function(
&mut self,
name: impl Into<String>,
signature: impl Into<PolyFuncType>,
) -> Result<FunctionBuilder<&mut Hugr>, BuildError> { ... }
fn add_hugr(&mut self, child: Hugr) -> InsertionResult { ... }
fn add_hugr_view(&mut self, child: &impl HugrView) -> InsertionResult { ... }
fn set_metadata(
&mut self,
key: impl AsRef<str>,
meta: impl Into<NodeMetadata>,
) { ... }
fn set_child_metadata(
&mut self,
child: Node,
key: impl AsRef<str>,
meta: impl Into<NodeMetadata>,
) { ... }
}
Expand description
Trait for HUGR container builders. Containers are nodes that are parents of sibling graphs. Implementations of this trait allow the child sibling graph to be added to the HUGR.
Required Methods§
sourcefn container_node(&self) -> Node
fn container_node(&self) -> Node
The container node.
Provided Methods§
sourcefn add_child_node(&mut self, node: impl Into<OpType>) -> Node
fn add_child_node(&mut self, node: impl Into<OpType>) -> Node
Add an OpType
as the final child of the container.
sourcefn add_other_wire(&mut self, src: Node, dst: Node) -> Wire
fn add_other_wire(&mut self, src: Node, dst: Node) -> Wire
Adds a non-dataflow edge between two nodes. The kind is given by the operation’s other_inputs
or other_outputs
sourcefn add_constant(&mut self, constant: impl Into<Const>) -> ConstID
fn add_constant(&mut self, constant: impl Into<Const>) -> ConstID
Add a constant value to the container and return a handle to it.
§Errors
This function will return an error if there is an error in adding the
OpType::Const
node.
sourcefn define_function(
&mut self,
name: impl Into<String>,
signature: impl Into<PolyFuncType>,
) -> Result<FunctionBuilder<&mut Hugr>, BuildError>
fn define_function( &mut self, name: impl Into<String>, signature: impl Into<PolyFuncType>, ) -> Result<FunctionBuilder<&mut Hugr>, BuildError>
Add a ops::FuncDefn
node and returns a builder to define the function
body graph.
§Errors
This function will return an error if there is an error in adding the
ops::FuncDefn
node.
sourcefn add_hugr(&mut self, child: Hugr) -> InsertionResult
fn add_hugr(&mut self, child: Hugr) -> InsertionResult
Insert a HUGR as a child of the container.
sourcefn add_hugr_view(&mut self, child: &impl HugrView) -> InsertionResult
fn add_hugr_view(&mut self, child: &impl HugrView) -> InsertionResult
Insert a copy of a HUGR as a child of the container.
sourcefn set_metadata(&mut self, key: impl AsRef<str>, meta: impl Into<NodeMetadata>)
fn set_metadata(&mut self, key: impl AsRef<str>, meta: impl Into<NodeMetadata>)
Add metadata to the container node.
sourcefn set_child_metadata(
&mut self,
child: Node,
key: impl AsRef<str>,
meta: impl Into<NodeMetadata>,
)
fn set_child_metadata( &mut self, child: Node, key: impl AsRef<str>, meta: impl Into<NodeMetadata>, )
Add metadata to a child node.
Returns an error if the specified child
is not a child of this container