pub trait HugrMut: HugrMutInternals {
Show 21 methods
// Provided methods
fn get_metadata_mut(
&mut self,
node: Node,
key: impl AsRef<str>,
) -> &mut NodeMetadata { ... }
fn set_metadata(
&mut self,
node: Node,
key: impl AsRef<str>,
metadata: impl Into<NodeMetadata>,
) { ... }
fn remove_metadata(&mut self, node: Node, key: impl AsRef<str>) { ... }
fn take_node_metadata(
&mut self,
node: Self::Node,
) -> Option<NodeMetadataMap> { ... }
fn overwrite_node_metadata(
&mut self,
node: Node,
metadata: Option<NodeMetadataMap>,
) { ... }
fn add_node_with_parent(
&mut self,
parent: Node,
op: impl Into<OpType>,
) -> Node { ... }
fn add_node_before(
&mut self,
sibling: Node,
nodetype: impl Into<OpType>,
) -> Node { ... }
fn add_node_after(&mut self, sibling: Node, op: impl Into<OpType>) -> Node { ... }
fn remove_node(&mut self, node: Node) -> OpType { ... }
fn remove_subtree(&mut self, node: Node) { ... }
fn copy_descendants(
&mut self,
root: Node,
new_parent: Node,
subst: Option<Substitution<'_>>,
) -> BTreeMap<Node, Node> { ... }
fn connect(
&mut self,
src: Node,
src_port: impl Into<OutgoingPort>,
dst: Node,
dst_port: impl Into<IncomingPort>,
) { ... }
fn disconnect(&mut self, node: Node, port: impl Into<Port>) { ... }
fn add_other_edge(
&mut self,
src: Node,
dst: Node,
) -> (OutgoingPort, IncomingPort) { ... }
fn insert_hugr(&mut self, root: Node, other: Hugr) -> InsertionResult { ... }
fn insert_from_view(
&mut self,
root: Node,
other: &impl HugrView,
) -> InsertionResult { ... }
fn insert_subgraph(
&mut self,
root: Node,
other: &impl HugrView,
subgraph: &SiblingSubgraph,
) -> HashMap<Node, Node> { ... }
fn apply_rewrite<R, E>(
&mut self,
rw: impl Rewrite<ApplyResult = R, Error = E>,
) -> Result<R, E>
where Self: Sized { ... }
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> { ... }
fn extensions_mut(&mut self) -> &mut ExtensionRegistry { ... }
}Expand description
Functions for low-level building of a HUGR.
Provided Methods§
Sourcefn get_metadata_mut(
&mut self,
node: Node,
key: impl AsRef<str>,
) -> &mut NodeMetadata
fn get_metadata_mut( &mut self, node: Node, key: impl AsRef<str>, ) -> &mut NodeMetadata
Sourcefn set_metadata(
&mut self,
node: Node,
key: impl AsRef<str>,
metadata: impl Into<NodeMetadata>,
)
fn set_metadata( &mut self, node: Node, key: impl AsRef<str>, metadata: impl Into<NodeMetadata>, )
Sourcefn remove_metadata(&mut self, node: Node, key: impl AsRef<str>)
fn remove_metadata(&mut self, node: Node, key: impl AsRef<str>)
Sourcefn take_node_metadata(&mut self, node: Self::Node) -> Option<NodeMetadataMap>
fn take_node_metadata(&mut self, node: Self::Node) -> Option<NodeMetadataMap>
Retrieve the complete metadata map for a node.
Sourcefn overwrite_node_metadata(
&mut self,
node: Node,
metadata: Option<NodeMetadataMap>,
)
fn overwrite_node_metadata( &mut self, node: Node, metadata: Option<NodeMetadataMap>, )
Sourcefn add_node_with_parent(&mut self, parent: Node, op: impl Into<OpType>) -> Node
fn add_node_with_parent(&mut self, parent: Node, op: impl Into<OpType>) -> 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: Node,
nodetype: impl Into<OpType>,
) -> Node
fn add_node_before( &mut self, sibling: Node, nodetype: impl Into<OpType>, ) -> 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: Node, op: impl Into<OpType>) -> Node
fn add_node_after(&mut self, sibling: Node, op: impl Into<OpType>) -> 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: Node) -> OpType
fn remove_node(&mut self, node: 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: Node)
fn remove_subtree(&mut self, node: 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: Node,
new_parent: Node,
subst: Option<Substitution<'_>>,
) -> BTreeMap<Node, Node>
fn copy_descendants( &mut self, root: Node, new_parent: Node, subst: Option<Substitution<'_>>, ) -> BTreeMap<Node, 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 or ExitBlock nodes 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: Node,
src_port: impl Into<OutgoingPort>,
dst: Node,
dst_port: impl Into<IncomingPort>,
)
fn connect( &mut self, src: Node, src_port: impl Into<OutgoingPort>, dst: 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: Node, port: impl Into<Port>)
fn disconnect(&mut self, node: 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: Node,
dst: Node,
) -> (OutgoingPort, IncomingPort)
fn add_other_edge( &mut self, src: Node, dst: 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_hugr(&mut self, root: Node, other: Hugr) -> InsertionResult
fn insert_hugr(&mut self, root: Node, other: Hugr) -> InsertionResult
Insert another hugr into this one, under a given root node.
§Panics
If the root node is not in the graph.
Sourcefn insert_from_view(
&mut self,
root: Node,
other: &impl HugrView,
) -> InsertionResult
fn insert_from_view( &mut self, root: Node, other: &impl HugrView, ) -> InsertionResult
Copy another hugr into this one, under a given root node.
§Panics
If the root node is not in the graph.
Sourcefn insert_subgraph(
&mut self,
root: Node,
other: &impl HugrView,
subgraph: &SiblingSubgraph,
) -> HashMap<Node, Node>
fn insert_subgraph( &mut self, root: Node, other: &impl HugrView, subgraph: &SiblingSubgraph, ) -> HashMap<Node, Node>
Copy a subgraph from another hugr into this one, under a given root 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 apply_rewrite<R, E>(
&mut self,
rw: impl Rewrite<ApplyResult = R, Error = E>,
) -> Result<R, E>where
Self: Sized,
fn apply_rewrite<R, E>(
&mut self,
rw: impl Rewrite<ApplyResult = R, Error = E>,
) -> Result<R, E>where
Self: Sized,
Applies a rewrite to 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.
Sourcefn extensions_mut(&mut self) -> &mut ExtensionRegistry
fn extensions_mut(&mut self) -> &mut ExtensionRegistry
Returns a mutable reference to the extension registry for this hugr.
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§
impl<H: HugrMutInternals + AsRef<Hugr>, Root: NodeHandle> HugrMut for RootChecked<H, Root>
impl<Root: NodeHandle> HugrMut for SiblingMut<'_, Root>
impl<T: RootTagged<RootHandle = Node, Node = Node> + AsMut<Hugr>> HugrMut for T
Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.