Trait HugrMut

Source
pub trait HugrMut: HugrMutInternals {
Show 21 methods // Required methods fn set_entrypoint(&mut self, root: Self::Node); fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata; fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, ); fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>); fn add_node_with_parent( &mut self, parent: Self::Node, op: impl Into<OpType>, ) -> Self::Node; fn add_node_before( &mut self, sibling: Self::Node, nodetype: impl Into<OpType>, ) -> Self::Node; fn add_node_after( &mut self, sibling: Self::Node, op: impl Into<OpType>, ) -> Self::Node; fn remove_node(&mut self, node: Self::Node) -> OpType; fn remove_subtree(&mut self, node: Self::Node); fn copy_descendants( &mut self, root: Self::Node, new_parent: Self::Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Self::Node, Self::Node>; fn connect( &mut self, src: Self::Node, src_port: impl Into<OutgoingPort>, dst: Self::Node, dst_port: impl Into<IncomingPort>, ); fn disconnect(&mut self, node: Self::Node, port: impl Into<Port>); fn add_other_edge( &mut self, src: Self::Node, dst: Self::Node, ) -> (OutgoingPort, IncomingPort); fn insert_region( &mut self, root: Self::Node, other: Hugr, region: Node, ) -> InsertionResult<Node, Self::Node>; fn insert_from_view<H: HugrView>( &mut self, root: Self::Node, other: &H, ) -> InsertionResult<H::Node, Self::Node>; fn insert_subgraph<H: HugrView>( &mut self, root: Self::Node, other: &H, subgraph: &SiblingSubgraph<H::Node>, ) -> HashMap<H::Node, Self::Node>; fn use_extension(&mut self, extension: impl Into<Arc<Extension>>); fn use_extensions<Reg>(&mut self, registry: impl IntoIterator<Item = Reg>) where ExtensionRegistry: Extend<Reg>; // Provided methods fn with_entrypoint_mut( &mut self, entrypoint: Self::Node, ) -> Rerooted<&mut Self> where Self: Sized { ... } fn insert_hugr( &mut self, root: Self::Node, other: Hugr, ) -> InsertionResult<Node, Self::Node> { ... } fn apply_patch<R, E>( &mut self, rw: impl Patch<Self, Outcome = R, Error = E>, ) -> Result<R, E> where Self: Sized { ... }
}
Expand description

Functions for low-level building of a HUGR.

Required Methods§

Source

fn set_entrypoint(&mut self, root: Self::Node)

Set entrypoint to the HUGR.

This node represents the execution entrypoint of the HUGR. When running local graph analysis or optimizations, the region defined under this node will be used as the starting point.

For the hugr to remain valid, the entrypoint must be a region-container node, i.e. a node that can have children in the hierarchy.

To get a borrowed view of the HUGR with a different entrypoint, use HugrView::with_entrypoint or HugrMut::with_entrypoint_mut instead.

§Panics

If the node is not in the graph.

Source

fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata

Returns a metadata entry associated with a node.

§Panics

If the node is not in the graph.

Source

fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )

Sets a metadata value associated with a node.

§Panics

If the node is not in the graph.

Source

fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)

Remove a metadata entry associated with a node.

§Panics

If the node is not in the graph.

Source

fn add_node_with_parent( &mut self, parent: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Add a node to the graph with a parent in the hierarchy.

The node becomes the parent’s last child.

§Panics

If the parent is not in the graph.

Source

fn add_node_before( &mut self, sibling: Self::Node, nodetype: impl Into<OpType>, ) -> Self::Node

Add a node to the graph as the previous sibling of another node.

The sibling node’s parent becomes the new node’s parent.

§Panics

If the sibling is not in the graph, or if the sibling is the root node.

Source

fn add_node_after( &mut self, sibling: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Add a node to the graph as the next sibling of another node.

The sibling node’s parent becomes the new node’s parent.

§Panics

If the sibling is not in the graph, or if the sibling is the root node.

Source

fn remove_node(&mut self, node: Self::Node) -> OpType

Remove a node from the graph and return the node weight. Note that if the node has children, they are not removed; this leaves the Hugr in an invalid state. See Self::remove_subtree.

§Panics

If the node is not in the graph, or if the node is the root node.

Source

fn remove_subtree(&mut self, node: Self::Node)

Remove a node from the graph, along with all its descendants in the hierarchy.

§Panics

If the node is not in the graph, or is the root (this would leave an empty Hugr).

Source

fn copy_descendants( &mut self, root: Self::Node, new_parent: Self::Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Self::Node, Self::Node>

Copies the strict descendants of root to under the new_parent, optionally applying a Substitution to the OpTypes of the copied nodes.

That is, the immediate children of root, are copied to make children of new_parent.

Note this may invalidate the Hugr in two ways:

  • Adding children of root may make the children-list of new_parent invalid e.g. leading to multiple Input, Output or ExitBlock nodes or Input/Output in the wrong positions
  • Nonlocal edges incoming to the subtree of root will be copied to target the subtree under new_parent which may be invalid if new_parent is not a child of roots parent (for Ext edges - or correspondingly for Dom edges)
Source

fn connect( &mut self, src: Self::Node, src_port: impl Into<OutgoingPort>, dst: Self::Node, dst_port: impl Into<IncomingPort>, )

Connect two nodes at the given ports.

§Panics

If either node is not in the graph or if the ports are invalid.

Source

fn disconnect(&mut self, node: Self::Node, port: impl Into<Port>)

Disconnects all edges from the given port.

The port is left in place.

§Panics

If the node is not in the graph, or if the port is invalid.

Source

fn add_other_edge( &mut self, src: Self::Node, dst: Self::Node, ) -> (OutgoingPort, IncomingPort)

Adds a non-dataflow edge between two nodes. The kind is given by the operation’s OpTrait::other_input or OpTrait::other_output.

Returns the offsets of the new input and output ports.

§Panics

If the node is not in the graph, or if the port is invalid.

Source

fn insert_region( &mut self, root: Self::Node, other: Hugr, region: Node, ) -> InsertionResult<Node, Self::Node>

Insert a sub-region of another hugr into this one, under a given parent node.

§Panics
  • If the root node is not in the graph.
  • If the region node is not in other.
Source

fn insert_from_view<H: HugrView>( &mut self, root: Self::Node, other: &H, ) -> InsertionResult<H::Node, Self::Node>

Copy another hugr into this one, under a given parent node.

§Panics

If the root node is not in the graph.

Source

fn insert_subgraph<H: HugrView>( &mut self, root: Self::Node, other: &H, subgraph: &SiblingSubgraph<H::Node>, ) -> HashMap<H::Node, Self::Node>

Copy a subgraph from another hugr into this one, under a given parent node.

Sibling order is not preserved.

The return value is a map from indices in other to the indices of the corresponding new nodes in self.

§Panics

If the root node is not in the graph.

Source

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

Registers a new extension in the set used by the hugr, keeping the one most recent one if the extension already exists.

These can be queried using HugrView::extensions.

See ExtensionRegistry::register_updated for more information.

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.

For each extension, keeps the most recent version if the id already exists.

These can be queried using HugrView::extensions.

See ExtensionRegistry::register_updated for more information.

Provided Methods§

Source

fn with_entrypoint_mut(&mut self, entrypoint: Self::Node) -> Rerooted<&mut Self>
where Self: Sized,

Returns a mutable view of the HUGR with a different entrypoint.

Changes to the returned HUGR affect the original one, and overwriting the entrypoint sets it both in the wrapper and the wrapped HUGR.

For a non-mut view, use HugrView::with_entrypoint instead.

§Panics

Panics if the entrypoint node is not valid in the HUGR.

Source

fn insert_hugr( &mut self, root: Self::Node, other: Hugr, ) -> InsertionResult<Node, Self::Node>

Insert another hugr into this one, under a given parent node.

§Panics

If the root node is not in the graph.

Source

fn apply_patch<R, E>( &mut self, rw: impl Patch<Self, Outcome = R, Error = E>, ) -> Result<R, E>
where Self: Sized,

Applies a patch to the graph.

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.

Implementations on Foreign Types§

Source§

impl<T> HugrMut for Cow<'_, T>
where T: HugrMut + ToOwned, <T as ToOwned>::Owned: HugrMut<Node = T::Node>,

Source§

fn set_entrypoint(&mut self, root: Self::Node)

Source§

fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata

Source§

fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )

Source§

fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)

Source§

fn add_node_with_parent( &mut self, parent: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_before( &mut self, sibling: Self::Node, nodetype: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_after( &mut self, sibling: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn remove_node(&mut self, node: Self::Node) -> OpType

Source§

fn remove_subtree(&mut self, node: Self::Node)

Source§

fn copy_descendants( &mut self, root: Self::Node, new_parent: Self::Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Self::Node, Self::Node>

Source§

fn connect( &mut self, src: Self::Node, src_port: impl Into<OutgoingPort>, dst: Self::Node, dst_port: impl Into<IncomingPort>, )

Source§

fn disconnect(&mut self, node: Self::Node, port: impl Into<Port>)

Source§

fn add_other_edge( &mut self, src: Self::Node, dst: Self::Node, ) -> (OutgoingPort, IncomingPort)

Source§

fn insert_hugr( &mut self, root: Self::Node, other: Hugr, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_region( &mut self, root: Self::Node, other: Hugr, region: Node, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_from_view<Other: HugrView>( &mut self, root: Self::Node, other: &Other, ) -> InsertionResult<Other::Node, Self::Node>

Source§

fn insert_subgraph<Other: HugrView>( &mut self, root: Self::Node, other: &Other, subgraph: &SiblingSubgraph<Other::Node>, ) -> HashMap<Other::Node, Self::Node>

Source§

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

Source§

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

Source§

impl<T: HugrMut> HugrMut for &mut T

Source§

fn set_entrypoint(&mut self, root: Self::Node)

Source§

fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata

Source§

fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )

Source§

fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)

Source§

fn add_node_with_parent( &mut self, parent: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_before( &mut self, sibling: Self::Node, nodetype: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_after( &mut self, sibling: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn remove_node(&mut self, node: Self::Node) -> OpType

Source§

fn remove_subtree(&mut self, node: Self::Node)

Source§

fn copy_descendants( &mut self, root: Self::Node, new_parent: Self::Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Self::Node, Self::Node>

Source§

fn connect( &mut self, src: Self::Node, src_port: impl Into<OutgoingPort>, dst: Self::Node, dst_port: impl Into<IncomingPort>, )

Source§

fn disconnect(&mut self, node: Self::Node, port: impl Into<Port>)

Source§

fn add_other_edge( &mut self, src: Self::Node, dst: Self::Node, ) -> (OutgoingPort, IncomingPort)

Source§

fn insert_hugr( &mut self, root: Self::Node, other: Hugr, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_region( &mut self, root: Self::Node, other: Hugr, region: Node, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_from_view<Other: HugrView>( &mut self, root: Self::Node, other: &Other, ) -> InsertionResult<Other::Node, Self::Node>

Source§

fn insert_subgraph<Other: HugrView>( &mut self, root: Self::Node, other: &Other, subgraph: &SiblingSubgraph<Other::Node>, ) -> HashMap<Other::Node, Self::Node>

Source§

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

Source§

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

Source§

impl<T: HugrMut> HugrMut for Box<T>

Source§

fn set_entrypoint(&mut self, root: Self::Node)

Source§

fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata

Source§

fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )

Source§

fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)

Source§

fn add_node_with_parent( &mut self, parent: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_before( &mut self, sibling: Self::Node, nodetype: impl Into<OpType>, ) -> Self::Node

Source§

fn add_node_after( &mut self, sibling: Self::Node, op: impl Into<OpType>, ) -> Self::Node

Source§

fn remove_node(&mut self, node: Self::Node) -> OpType

Source§

fn remove_subtree(&mut self, node: Self::Node)

Source§

fn copy_descendants( &mut self, root: Self::Node, new_parent: Self::Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Self::Node, Self::Node>

Source§

fn connect( &mut self, src: Self::Node, src_port: impl Into<OutgoingPort>, dst: Self::Node, dst_port: impl Into<IncomingPort>, )

Source§

fn disconnect(&mut self, node: Self::Node, port: impl Into<Port>)

Source§

fn add_other_edge( &mut self, src: Self::Node, dst: Self::Node, ) -> (OutgoingPort, IncomingPort)

Source§

fn insert_hugr( &mut self, root: Self::Node, other: Hugr, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_region( &mut self, root: Self::Node, other: Hugr, region: Node, ) -> InsertionResult<Node, Self::Node>

Source§

fn insert_from_view<Other: HugrView>( &mut self, root: Self::Node, other: &Other, ) -> InsertionResult<Other::Node, Self::Node>

Source§

fn insert_subgraph<Other: HugrView>( &mut self, root: Self::Node, other: &Other, subgraph: &SiblingSubgraph<Other::Node>, ) -> HashMap<Other::Node, Self::Node>

Source§

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

Source§

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

Implementors§

Source§

impl HugrMut for Hugr

Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.

Source§

impl<H: HugrMut> HugrMut for Rerooted<H>