Trait hugr_core::hugr::internal::HugrMutInternals
source · pub trait HugrMutInternals: RootTagged {
// Required method
fn hugr_mut(&mut self) -> &mut Hugr;
// Provided methods
fn set_num_ports(&mut self, node: Node, incoming: usize, outgoing: usize) { ... }
fn add_ports(
&mut self,
node: Node,
direction: Direction,
amount: isize,
) -> Range<usize> { ... }
fn set_parent(&mut self, node: Node, parent: Node) { ... }
fn move_after_sibling(&mut self, node: Node, after: Node) { ... }
fn move_before_sibling(&mut self, node: Node, before: Node) { ... }
fn replace_op(
&mut self,
node: Node,
op: impl Into<OpType>,
) -> Result<OpType, HugrError> { ... }
}
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§
Provided Methods§
sourcefn set_num_ports(&mut self, node: Node, incoming: usize, outgoing: usize)
fn set_num_ports(&mut self, node: 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: Node,
direction: Direction,
amount: isize,
) -> Range<usize>
fn add_ports( &mut self, node: 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.
§Panics
If the node is not in the graph.
sourcefn set_parent(&mut self, node: Node, parent: Node)
fn set_parent(&mut self, node: Node, parent: 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: Node, after: Node)
fn move_after_sibling(&mut self, node: Node, after: 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: Node, before: Node)
fn move_before_sibling(&mut self, node: Node, before: 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: Node,
op: impl Into<OpType>,
) -> Result<OpType, HugrError>
fn replace_op( &mut self, node: Node, op: impl Into<OpType>, ) -> Result<OpType, HugrError>
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. TODO: Add a version which ignores input extensions
§Errors
Returns a HugrError::InvalidTag
if this would break the bound
(Self::RootHandle
) on the root node’s OpTag.
§Panics
If the node is not in the graph.
Object Safety§
Implementors§
impl<'g, Root: NodeHandle> HugrMutInternals for SiblingMut<'g, Root>
impl<H: HugrMutInternals + AsRef<Hugr>, Root> HugrMutInternals for RootChecked<H, Root>where
Root: NodeHandle,
impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMutInternals for T
Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.