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§

source

fn hugr_mut(&mut self) -> &mut Hugr

Returns the Hugr at the base of a chain of views.

Provided Methods§

source

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.

source

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.

source

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.

source

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.

source

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.

source

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§

This trait is not object safe.

Implementors§

source§

impl<'g, Root: NodeHandle> HugrMutInternals for SiblingMut<'g, Root>

source§

impl<H: HugrMutInternals + AsRef<Hugr>, Root> HugrMutInternals for RootChecked<H, Root>
where Root: NodeHandle,

source§

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.