Trait HugrMutInternals

Source
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§

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap

Returns a metadata entry associated with a node.

§Panics

If the node is not in the graph.

Source

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>
where T: HugrMutInternals + ToOwned, <T as ToOwned>::Owned: HugrMutInternals<Node = T::Node>,

Source§

fn set_module_root(&mut self, root: Self::Node)

Source§

fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)

Source§

fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>

Source§

fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>

Source§

fn set_parent(&mut self, node: Self::Node, parent: Self::Node)

Source§

fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)

Source§

fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)

Source§

fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType

Source§

fn optype_mut(&mut self, node: Self::Node) -> &mut OpType

Source§

fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap

Source§

fn extensions_mut(&mut self) -> &mut ExtensionRegistry

Source§

impl<T: HugrMutInternals> HugrMutInternals for &mut T

Source§

fn set_module_root(&mut self, root: Self::Node)

Source§

fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)

Source§

fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>

Source§

fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>

Source§

fn set_parent(&mut self, node: Self::Node, parent: Self::Node)

Source§

fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)

Source§

fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)

Source§

fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType

Source§

fn optype_mut(&mut self, node: Self::Node) -> &mut OpType

Source§

fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap

Source§

fn extensions_mut(&mut self) -> &mut ExtensionRegistry

Source§

impl<T: HugrMutInternals> HugrMutInternals for Box<T>

Source§

fn set_module_root(&mut self, root: Self::Node)

Source§

fn set_num_ports(&mut self, node: Self::Node, incoming: usize, outgoing: usize)

Source§

fn add_ports( &mut self, node: Self::Node, direction: Direction, amount: isize, ) -> Range<usize>

Source§

fn insert_ports( &mut self, node: Self::Node, direction: Direction, index: usize, amount: usize, ) -> Range<usize>

Source§

fn set_parent(&mut self, node: Self::Node, parent: Self::Node)

Source§

fn move_after_sibling(&mut self, node: Self::Node, after: Self::Node)

Source§

fn move_before_sibling(&mut self, node: Self::Node, before: Self::Node)

Source§

fn replace_op(&mut self, node: Self::Node, op: impl Into<OpType>) -> OpType

Source§

fn optype_mut(&mut self, node: Self::Node) -> &mut OpType

Source§

fn node_metadata_map_mut(&mut self, node: Self::Node) -> &mut NodeMetadataMap

Source§

fn extensions_mut(&mut self) -> &mut ExtensionRegistry

Implementors§

Source§

impl HugrMutInternals for Hugr

Impl for non-wrapped Hugrs. Overwrites the recursive default-impls to directly use the hugr.

Source§

impl<H: HugrMutInternals> HugrMutInternals for Rerooted<H>