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 add_hugr(&mut self, child: Hugr) -> InsertionResult { ... }
    fn add_hugr_view<H: HugrView>(
        &mut self,
        child: &H,
    ) -> InsertionResult<H::Node, Node> { ... }
    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>,
    ) { ... }
    fn use_extension(&mut self, ext: impl Into<Arc<Extension>>) { ... }
    fn use_extensions<Reg>(&mut self, registry: impl IntoIterator<Item = Reg>)
       where ExtensionRegistry: Extend<Reg> { ... }
}
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.

Adds the extensions required by the op to the HUGR, if they are not already present.

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.

Adds the extensions required by the op to the HUGR, if they are not already present.

§Errors

This function will return an error if there is an error in adding the OpType::Const node.

Source

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

Insert a HUGR as a child of the container.

Source

fn add_hugr_view<H: HugrView>( &mut self, child: &H, ) -> InsertionResult<H::Node, Node>

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

Source

fn use_extension(&mut self, ext: impl Into<Arc<Extension>>)

Add an extension to the set of extensions used by the hugr.

Source

fn use_extensions<Reg>(&mut self, registry: impl IntoIterator<Item = Reg>)

Extend the set of extensions used by the hugr with the extensions in the registry.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§