pub trait HugrMutInternals: HugrView {
// Required methods
fn set_module_root(&mut self, root: Self::Node);
fn set_num_ports(
&mut self,
node: Self::Node,
incoming: usize,
outgoing: usize,
);
fn add_ports(
&mut self,
node: Self::Node,
direction: Direction,
amount: isize,
) -> Range<usize>;
fn insert_ports(
&mut self,
node: Self::Node,
direction: Direction,
index: usize,
amount: usize,
) -> Range<usize>;
fn set_parent(&mut self, node: Self::Node, parent: Self::Node);
fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node);
fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node);
fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType;
fn optype_mut(&mut self, node: Self::Node) -> &mut OpType;
fn node_metadata_map_mut(
&mut self,
node: Self::Node,
) -> &mut NodeMetadataMap;
fn extensions_mut(&mut self) -> &mut ExtensionRegistry;
}
Expand description
Trait for accessing the mutable internals of a Hugr(Mut).
Specifically, this trait lets you apply arbitrary modifications that may invalidate the HUGR.
Required Methods§
Sourcefn set_module_root(&mut self, root: Self::Node)
fn set_module_root(&mut self, root: Self::Node)
Set the node at the root of the HUGR hierarchy.
Any node not reachable from this root should be manually removed from the HUGR.
To set the working entrypoint of the HUGR, use
HugrMut::set_entrypoint
instead.
§Panics
If the node is not in the graph.
Sourcefn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)
fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)
Set the number of ports on a node. This may invalidate the node’s PortIndex
.
§Panics
If the node is not in the graph.
Sourcefn add_ports(
&mut self,
node: Self::Node,
direction: Direction,
amount: isize,
) -> Range<usize>
fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>
Alter the number of ports on a node and returns a range with the new
port offsets, if any. This may invalidate the node’s PortIndex
.
The direction
parameter specifies whether to add ports to the incoming
or outgoing list.
Returns the range of newly created ports.
§Panics
If the node is not in the graph.
Sourcefn insert_ports(
&mut self,
node: Self::Node,
direction: Direction,
index: usize,
amount: usize,
) -> Range<usize>
fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>
Insert amount
new ports for a node, starting at index
. The
direction
parameter specifies whether to add ports to the incoming or
outgoing list. Links from this node are preserved, even when ports are
renumbered by the insertion.
Returns the range of newly created ports.
§Panics
If the node is not in the graph.
Sourcefn set_parent(&mut self, node: Self::Node, parent: Self::Node)
fn set_parent(&mut self, node: Self::Node, parent: Self::Node)
Sets the parent of a node.
The node becomes the parent’s last child.
§Panics
If either the node or the parent is not in the graph.
Sourcefn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)
fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)
Move a node in the hierarchy to be the subsequent sibling of another node.
The sibling node’s parent becomes the new node’s parent.
The node becomes the parent’s last child.
§Panics
If either node is not in the graph, or if it is a root.
Sourcefn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)
fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)
Move a node in the hierarchy to be the prior sibling of another node.
The sibling node’s parent becomes the new node’s parent.
The node becomes the parent’s last child.
§Panics
If either node is not in the graph, or if it is a root.
Sourcefn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType
fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType
Replace the OpType
at node and return the old OpType
.
In general this invalidates the ports, which may need to be resized to
match the OpType
signature.
Returns the old OpType
.
If the module root is set to a non-module operation the hugr will become invalid.
§Panics
If the node is not in the graph.
Sourcefn optype_mut(&mut self, node: Self::Node) -> &mut OpType
fn optype_mut(&mut self, node: Self::Node) -> &mut OpType
Gets a mutable reference to the optype.
Changing this may invalidate the ports, which may need to be resized to
match the OpType
signature.
Mutating the root node operation may invalidate the root tag.
Mutating the module root into a non-module operation will invalidate the hugr.
§Panics
If the node is not in the graph.
Sourcefn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap
fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap
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.
This set contains all extensions required to define the operations and types in the 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.
Implementations on Foreign Types§
Source§impl<T> HugrMutInternals for Cow<'_, T>
impl<T> HugrMutInternals for Cow<'_, T>
fn set_module_root(&mut self, root: Self::Node)
fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)
fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>
fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>
fn set_parent(&mut self, node: Self::Node, parent: Self::Node)
fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)
fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)
fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType
fn optype_mut(&mut self, node: Self::Node) -> &mut OpType
fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap
fn extensions_mut(&mut self) -> &mut ExtensionRegistry
Source§impl<T: HugrMutInternals> HugrMutInternals for &mut T
impl<T: HugrMutInternals> HugrMutInternals for &mut T
fn set_module_root(&mut self, root: Self::Node)
fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)
fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>
fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>
fn set_parent(&mut self, node: Self::Node, parent: Self::Node)
fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)
fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)
fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType
fn optype_mut(&mut self, node: Self::Node) -> &mut OpType
fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap
fn extensions_mut(&mut self) -> &mut ExtensionRegistry
Source§impl<T: HugrMutInternals> HugrMutInternals for Box<T>
impl<T: HugrMutInternals> HugrMutInternals for Box<T>
fn set_module_root(&mut self, root: Self::Node)
fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)
fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>
fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>
fn set_parent(&mut self, node: Self::Node, parent: Self::Node)
fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)
fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)
fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType
fn optype_mut(&mut self, node: Self::Node) -> &mut OpType
fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap
fn extensions_mut(&mut self) -> &mut ExtensionRegistry
Implementors§
impl HugrMutInternals for Hugr
Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.