hugr_core::builder

Trait Container

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

source

fn container_node(&self) -> Node

The container node.

source

fn hugr_mut(&mut self) -> &mut Hugr

The underlying Hugr being built

source

fn hugr(&self) -> &Hugr

Immutable reference to HUGR being built

Provided Methods§

source

fn add_child_node(&mut self, node: impl Into<OpType>) -> Node

Add an OpType as the final child of the container.

source

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

source

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.

source

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.

source

fn add_hugr(&mut self, child: Hugr) -> InsertionResult

Insert a HUGR as a child of the container.

source

fn add_hugr_view(&mut self, child: &impl HugrView) -> InsertionResult

Insert a copy of a HUGR as a child of the container.

source

fn set_metadata(&mut self, key: impl AsRef<str>, meta: impl Into<NodeMetadata>)

Add metadata to the container node.

source

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

Object Safety§

This trait is not object safe.

Implementors§