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§
Sourcefn set_entrypoint(&mut self, root: Self::Node)
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.
Sourcefn get_metadata_mut(
&mut self,
node: Self::Node,
key: impl AsRef<str>,
) -> &mut NodeMetadata
fn get_metadata_mut( &mut self, node: Self::Node, key: impl AsRef<str>, ) -> &mut NodeMetadata
Sourcefn set_metadata(
&mut self,
node: Self::Node,
key: impl AsRef<str>,
metadata: impl Into<NodeMetadata>,
)
fn set_metadata( &mut self, node: Self::Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )
Sourcefn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)
fn remove_metadata(&mut self, node: Self::Node, key: impl AsRef<str>)
Sourcefn add_node_with_parent(
&mut self,
parent: Self::Node,
op: impl Into<OpType>,
) -> Self::Node
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.
Sourcefn add_node_before(
&mut self,
sibling: Self::Node,
nodetype: impl Into<OpType>,
) -> Self::Node
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.
Sourcefn add_node_after(
&mut self,
sibling: Self::Node,
op: impl Into<OpType>,
) -> Self::Node
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.
Sourcefn remove_node(&mut self, node: Self::Node) -> OpType
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.
Sourcefn remove_subtree(&mut self, node: Self::Node)
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).
Sourcefn copy_descendants(
&mut self,
root: Self::Node,
new_parent: Self::Node,
subst: Option<Substitution<'_>>,
) -> BTreeMap<Self::Node, Self::Node>
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
rootmay make the children-list ofnew_parentinvalid e.g. leading to multiple Input, Output orExitBlocknodes or Input/Output in the wrong positions - Nonlocal edges incoming to the subtree of
rootwill be copied to target the subtree undernew_parentwhich may be invalid ifnew_parentis not a child ofroots parent (forExtedges - or correspondingly forDomedges)
Sourcefn connect(
&mut self,
src: Self::Node,
src_port: impl Into<OutgoingPort>,
dst: Self::Node,
dst_port: impl Into<IncomingPort>,
)
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.
Sourcefn disconnect(&mut self, node: Self::Node, port: impl Into<Port>)
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.
Sourcefn add_other_edge(
&mut self,
src: Self::Node,
dst: Self::Node,
) -> (OutgoingPort, IncomingPort)
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.
Sourcefn insert_region(
&mut self,
root: Self::Node,
other: Hugr,
region: Node,
) -> InsertionResult<Node, Self::Node>
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
regionnode is not inother.
Sourcefn insert_from_view<H: HugrView>(
&mut self,
root: Self::Node,
other: &H,
) -> InsertionResult<H::Node, Self::Node>
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.
Sourcefn insert_subgraph<H: HugrView>(
&mut self,
root: Self::Node,
other: &H,
subgraph: &SiblingSubgraph<H::Node>,
) -> HashMap<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>
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.
Sourcefn use_extension(&mut self, extension: impl Into<Arc<Extension>>)
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.
Sourcefn use_extensions<Reg>(&mut self, registry: impl IntoIterator<Item = Reg>)where
ExtensionRegistry: Extend<Reg>,
fn use_extensions<Reg>(&mut self, registry: impl IntoIterator<Item = Reg>)where
ExtensionRegistry: Extend<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§
Sourcefn with_entrypoint_mut(&mut self, entrypoint: Self::Node) -> Rerooted<&mut Self>where
Self: Sized,
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.
Sourcefn insert_hugr(
&mut self,
root: Self::Node,
other: Hugr,
) -> InsertionResult<Node, Self::Node>
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.
Sourcefn apply_patch<R, E>(
&mut self,
rw: impl Patch<Self, Outcome = R, Error = E>,
) -> Result<R, E>where
Self: Sized,
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.