pub trait HugrView: HugrInternals {
Show 52 methods
// Required methods
fn contains_node(&self, node: Self::Node) -> bool;
fn node_count(&self) -> usize;
fn edge_count(&self) -> usize;
fn nodes(&self) -> impl Iterator<Item = Self::Node> + Clone;
fn node_ports(
&self,
node: Self::Node,
dir: Direction,
) -> impl Iterator<Item = Port> + Clone;
fn all_node_ports(
&self,
node: Self::Node,
) -> impl Iterator<Item = Port> + Clone;
fn linked_ports(
&self,
node: Self::Node,
port: impl Into<Port>,
) -> impl Iterator<Item = (Self::Node, Port)> + Clone;
fn node_connections(
&self,
node: Self::Node,
other: Self::Node,
) -> impl Iterator<Item = [Port; 2]> + Clone;
fn num_ports(&self, node: Self::Node, dir: Direction) -> usize;
fn children(
&self,
node: Self::Node,
) -> impl DoubleEndedIterator<Item = Self::Node> + Clone;
fn neighbours(
&self,
node: Self::Node,
dir: Direction,
) -> impl Iterator<Item = Self::Node> + Clone;
fn all_neighbours(
&self,
node: Self::Node,
) -> impl Iterator<Item = Self::Node> + Clone;
// Provided methods
fn root(&self) -> Self::Node { ... }
fn root_type(&self) -> &OpType { ... }
fn valid_node(&self, node: Self::Node) -> bool { ... }
fn valid_non_root(&self, node: Self::Node) -> bool { ... }
fn get_parent(&self, node: Self::Node) -> Option<Self::Node> { ... }
fn get_optype(&self, node: Self::Node) -> &OpType { ... }
fn get_metadata(
&self,
node: Self::Node,
key: impl AsRef<str>,
) -> Option<&NodeMetadata> { ... }
fn get_node_metadata(&self, node: Self::Node) -> Option<&NodeMetadataMap> { ... }
fn node_outputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = OutgoingPort> + Clone { ... }
fn node_inputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = IncomingPort> + Clone { ... }
fn all_linked_ports(
&self,
node: Self::Node,
dir: Direction,
) -> Either<impl Iterator<Item = (Self::Node, OutgoingPort)>, impl Iterator<Item = (Self::Node, IncomingPort)>> ⓘ { ... }
fn all_linked_outputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = (Self::Node, OutgoingPort)> { ... }
fn all_linked_inputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = (Self::Node, IncomingPort)> { ... }
fn single_linked_port(
&self,
node: Self::Node,
port: impl Into<Port>,
) -> Option<(Self::Node, Port)> { ... }
fn single_linked_output(
&self,
node: Self::Node,
port: impl Into<IncomingPort>,
) -> Option<(Self::Node, OutgoingPort)> { ... }
fn single_linked_input(
&self,
node: Self::Node,
port: impl Into<OutgoingPort>,
) -> Option<(Self::Node, IncomingPort)> { ... }
fn linked_outputs(
&self,
node: Self::Node,
port: impl Into<IncomingPort>,
) -> impl Iterator<Item = (Self::Node, OutgoingPort)> { ... }
fn linked_inputs(
&self,
node: Self::Node,
port: impl Into<OutgoingPort>,
) -> impl Iterator<Item = (Self::Node, IncomingPort)> { ... }
fn is_linked(&self, node: Self::Node, port: impl Into<Port>) -> bool { ... }
fn num_inputs(&self, node: Self::Node) -> usize { ... }
fn num_outputs(&self, node: Self::Node) -> usize { ... }
fn first_child(&self, node: Self::Node) -> Option<Self::Node> { ... }
fn input_neighbours(
&self,
node: Self::Node,
) -> impl Iterator<Item = Self::Node> + Clone { ... }
fn output_neighbours(
&self,
node: Self::Node,
) -> impl Iterator<Item = Self::Node> + Clone { ... }
fn get_io(&self, node: Self::Node) -> Option<[Self::Node; 2]> { ... }
fn inner_function_type(&self) -> Option<Cow<'_, Signature>> { ... }
fn poly_func_type(&self) -> Option<PolyFuncType> { ... }
fn as_petgraph(&self) -> PetgraphWrapper<'_, Self>
where Self: Sized { ... }
fn mermaid_string(&self) -> String { ... }
fn mermaid_string_with_config(&self, config: RenderConfig) -> String { ... }
fn dot_string(&self) -> String
where Self: Sized { ... }
fn static_source(&self, node: Self::Node) -> Option<Self::Node> { ... }
fn static_targets(
&self,
node: Self::Node,
) -> Option<impl Iterator<Item = (Self::Node, IncomingPort)>> { ... }
fn signature(&self, node: Self::Node) -> Option<Cow<'_, Signature>> { ... }
fn value_types(
&self,
node: Self::Node,
dir: Direction,
) -> impl Iterator<Item = (Port, Type)> { ... }
fn in_value_types(
&self,
node: Self::Node,
) -> impl Iterator<Item = (IncomingPort, Type)> { ... }
fn out_value_types(
&self,
node: Self::Node,
) -> impl Iterator<Item = (OutgoingPort, Type)> { ... }
fn extensions(&self) -> &ExtensionRegistry { ... }
fn validate(&self) -> Result<(), ValidationError> { ... }
fn validate_no_extensions(&self) -> Result<(), ValidationError> { ... }
}Expand description
A trait for inspecting HUGRs. For end users we intend this to be superseded by region-specific APIs.
Required Methods§
Sourcefn contains_node(&self, node: Self::Node) -> bool
fn contains_node(&self, node: Self::Node) -> bool
Returns whether the node exists.
Sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Returns the number of nodes in the hugr.
Sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Returns the number of edges in the hugr.
Sourcefn nodes(&self) -> impl Iterator<Item = Self::Node> + Clone
fn nodes(&self) -> impl Iterator<Item = Self::Node> + Clone
Iterates over the nodes in the port graph.
Sourcefn node_ports(
&self,
node: Self::Node,
dir: Direction,
) -> impl Iterator<Item = Port> + Clone
fn node_ports( &self, node: Self::Node, dir: Direction, ) -> impl Iterator<Item = Port> + Clone
Iterator over ports of node in a given direction.
Sourcefn all_node_ports(&self, node: Self::Node) -> impl Iterator<Item = Port> + Clone
fn all_node_ports(&self, node: Self::Node) -> impl Iterator<Item = Port> + Clone
Iterator over both the input and output ports of node.
Sourcefn linked_ports(
&self,
node: Self::Node,
port: impl Into<Port>,
) -> impl Iterator<Item = (Self::Node, Port)> + Clone
fn linked_ports( &self, node: Self::Node, port: impl Into<Port>, ) -> impl Iterator<Item = (Self::Node, Port)> + Clone
Iterator over the nodes and ports connected to a port.
Sourcefn node_connections(
&self,
node: Self::Node,
other: Self::Node,
) -> impl Iterator<Item = [Port; 2]> + Clone
fn node_connections( &self, node: Self::Node, other: Self::Node, ) -> impl Iterator<Item = [Port; 2]> + Clone
Iterator the links between two nodes.
Sourcefn num_ports(&self, node: Self::Node, dir: Direction) -> usize
fn num_ports(&self, node: Self::Node, dir: Direction) -> usize
Number of ports in node for a given direction.
Sourcefn children(
&self,
node: Self::Node,
) -> impl DoubleEndedIterator<Item = Self::Node> + Clone
fn children( &self, node: Self::Node, ) -> impl DoubleEndedIterator<Item = Self::Node> + Clone
Return iterator over the direct children of node.
Provided Methods§
Sourcefn valid_node(&self, node: Self::Node) -> bool
fn valid_node(&self, node: Self::Node) -> bool
Validates that a node is valid in the graph.
Sourcefn valid_non_root(&self, node: Self::Node) -> bool
fn valid_non_root(&self, node: Self::Node) -> bool
Validates that a node is a valid root descendant in the graph.
To include the root node use HugrView::valid_node instead.
Sourcefn get_parent(&self, node: Self::Node) -> Option<Self::Node>
fn get_parent(&self, node: Self::Node) -> Option<Self::Node>
Returns the parent of a node.
Sourcefn get_optype(&self, node: Self::Node) -> &OpType
fn get_optype(&self, node: Self::Node) -> &OpType
Returns the operation type of a node.
Sourcefn get_metadata(
&self,
node: Self::Node,
key: impl AsRef<str>,
) -> Option<&NodeMetadata>
fn get_metadata( &self, node: Self::Node, key: impl AsRef<str>, ) -> Option<&NodeMetadata>
Returns the metadata associated with a node.
Sourcefn get_node_metadata(&self, node: Self::Node) -> Option<&NodeMetadataMap>
fn get_node_metadata(&self, node: Self::Node) -> Option<&NodeMetadataMap>
Retrieve the complete metadata map for a node.
Sourcefn node_outputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = OutgoingPort> + Clone
fn node_outputs( &self, node: Self::Node, ) -> impl Iterator<Item = OutgoingPort> + Clone
Iterator over output ports of node.
Like node_ports(node, Direction::Outgoing)
but preserves knowledge that the ports are OutgoingPorts.
Sourcefn node_inputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = IncomingPort> + Clone
fn node_inputs( &self, node: Self::Node, ) -> impl Iterator<Item = IncomingPort> + Clone
Iterator over inputs ports of node.
Like node_ports(node, Direction::Incoming)
but preserves knowledge that the ports are IncomingPorts.
Sourcefn all_linked_ports(
&self,
node: Self::Node,
dir: Direction,
) -> Either<impl Iterator<Item = (Self::Node, OutgoingPort)>, impl Iterator<Item = (Self::Node, IncomingPort)>> ⓘ
fn all_linked_ports( &self, node: Self::Node, dir: Direction, ) -> Either<impl Iterator<Item = (Self::Node, OutgoingPort)>, impl Iterator<Item = (Self::Node, IncomingPort)>> ⓘ
Iterator over all the nodes and ports connected to a node in a given direction.
Sourcefn all_linked_outputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = (Self::Node, OutgoingPort)>
fn all_linked_outputs( &self, node: Self::Node, ) -> impl Iterator<Item = (Self::Node, OutgoingPort)>
Iterator over all the nodes and ports connected to a node’s inputs.
Sourcefn all_linked_inputs(
&self,
node: Self::Node,
) -> impl Iterator<Item = (Self::Node, IncomingPort)>
fn all_linked_inputs( &self, node: Self::Node, ) -> impl Iterator<Item = (Self::Node, IncomingPort)>
Iterator over all the nodes and ports connected to a node’s outputs.
Sourcefn single_linked_port(
&self,
node: Self::Node,
port: impl Into<Port>,
) -> Option<(Self::Node, Port)>
fn single_linked_port( &self, node: Self::Node, port: impl Into<Port>, ) -> Option<(Self::Node, Port)>
If there is exactly one port connected to this port, return it and its node.
Sourcefn single_linked_output(
&self,
node: Self::Node,
port: impl Into<IncomingPort>,
) -> Option<(Self::Node, OutgoingPort)>
fn single_linked_output( &self, node: Self::Node, port: impl Into<IncomingPort>, ) -> Option<(Self::Node, OutgoingPort)>
If there is exactly one OutgoingPort connected to this IncomingPort, return it and its node.
Sourcefn single_linked_input(
&self,
node: Self::Node,
port: impl Into<OutgoingPort>,
) -> Option<(Self::Node, IncomingPort)>
fn single_linked_input( &self, node: Self::Node, port: impl Into<OutgoingPort>, ) -> Option<(Self::Node, IncomingPort)>
If there is exactly one IncomingPort connected to this OutgoingPort, return it and its node.
Sourcefn linked_outputs(
&self,
node: Self::Node,
port: impl Into<IncomingPort>,
) -> impl Iterator<Item = (Self::Node, OutgoingPort)>
fn linked_outputs( &self, node: Self::Node, port: impl Into<IncomingPort>, ) -> impl Iterator<Item = (Self::Node, OutgoingPort)>
Iterator over the nodes and output ports connected to a given input port.
Like linked_ports but preserves knowledge
that the linked ports are OutgoingPorts.
Sourcefn linked_inputs(
&self,
node: Self::Node,
port: impl Into<OutgoingPort>,
) -> impl Iterator<Item = (Self::Node, IncomingPort)>
fn linked_inputs( &self, node: Self::Node, port: impl Into<OutgoingPort>, ) -> impl Iterator<Item = (Self::Node, IncomingPort)>
Iterator over the nodes and input ports connected to a given output port
Like linked_ports but preserves knowledge
that the linked ports are IncomingPorts.
Sourcefn is_linked(&self, node: Self::Node, port: impl Into<Port>) -> bool
fn is_linked(&self, node: Self::Node, port: impl Into<Port>) -> bool
Returns whether a port is connected.
Sourcefn num_inputs(&self, node: Self::Node) -> usize
fn num_inputs(&self, node: Self::Node) -> usize
Number of inputs to a node.
Shorthand for num_ports(node, Direction::Incoming).
Sourcefn num_outputs(&self, node: Self::Node) -> usize
fn num_outputs(&self, node: Self::Node) -> usize
Number of outputs from a node.
Shorthand for num_ports(node, Direction::Outgoing).
Sourcefn first_child(&self, node: Self::Node) -> Option<Self::Node>
fn first_child(&self, node: Self::Node) -> Option<Self::Node>
Returns the first child of the specified node (if it is a parent).
Useful because x.children().next() leaves x borrowed.
Sourcefn input_neighbours(
&self,
node: Self::Node,
) -> impl Iterator<Item = Self::Node> + Clone
fn input_neighbours( &self, node: Self::Node, ) -> impl Iterator<Item = Self::Node> + Clone
Iterates over the input neighbours of the node.
Shorthand for neighbours(node, Direction::Incoming).
Sourcefn output_neighbours(
&self,
node: Self::Node,
) -> impl Iterator<Item = Self::Node> + Clone
fn output_neighbours( &self, node: Self::Node, ) -> impl Iterator<Item = Self::Node> + Clone
Iterates over the output neighbours of the node.
Shorthand for neighbours(node, Direction::Outgoing).
Sourcefn get_io(&self, node: Self::Node) -> Option<[Self::Node; 2]>
fn get_io(&self, node: Self::Node) -> Option<[Self::Node; 2]>
Get the input and output child nodes of a dataflow parent. If the node isn’t a dataflow parent, then return None
Sourcefn inner_function_type(&self) -> Option<Cow<'_, Signature>>
fn inner_function_type(&self) -> Option<Cow<'_, Signature>>
Returns the function type defined by this dataflow HUGR.
If the root of the Hugr is a
DataflowParent operation, report the
signature corresponding to the input and output node of its sibling
graph. Otherwise, returns None.
In contrast to poly_func_type, this
method always return a concrete Signature.
Sourcefn poly_func_type(&self) -> Option<PolyFuncType>
fn poly_func_type(&self) -> Option<PolyFuncType>
Sourcefn as_petgraph(&self) -> PetgraphWrapper<'_, Self>where
Self: Sized,
fn as_petgraph(&self) -> PetgraphWrapper<'_, Self>where
Self: Sized,
Return a wrapper over the view that can be used in petgraph algorithms.
Sourcefn mermaid_string(&self) -> String
fn mermaid_string(&self) -> String
Return the mermaid representation of the underlying hierarchical graph.
The hierarchy is represented using subgraphs. Edges are labelled with their source and target ports.
For a more detailed representation, use the HugrView::dot_string
format instead.
Sourcefn mermaid_string_with_config(&self, config: RenderConfig) -> String
fn mermaid_string_with_config(&self, config: RenderConfig) -> String
Return the mermaid representation of the underlying hierarchical graph.
The hierarchy is represented using subgraphs. Edges are labelled with their source and target ports.
For a more detailed representation, use the HugrView::dot_string
format instead.
Sourcefn dot_string(&self) -> Stringwhere
Self: Sized,
fn dot_string(&self) -> Stringwhere
Self: Sized,
Return the graphviz representation of the underlying graph and hierarchy side by side.
For a simpler representation, use the HugrView::mermaid_string format instead.
Sourcefn static_source(&self, node: Self::Node) -> Option<Self::Node>
fn static_source(&self, node: Self::Node) -> Option<Self::Node>
If a node has a static input, return the source node.
Sourcefn static_targets(
&self,
node: Self::Node,
) -> Option<impl Iterator<Item = (Self::Node, IncomingPort)>>
fn static_targets( &self, node: Self::Node, ) -> Option<impl Iterator<Item = (Self::Node, IncomingPort)>>
If a node has a static output, return the targets.
Sourcefn signature(&self, node: Self::Node) -> Option<Cow<'_, Signature>>
fn signature(&self, node: Self::Node) -> Option<Cow<'_, Signature>>
Get the “signature” (incoming and outgoing types) of a node, non-Value kind ports will be missing.
Sourcefn value_types(
&self,
node: Self::Node,
dir: Direction,
) -> impl Iterator<Item = (Port, Type)>
fn value_types( &self, node: Self::Node, dir: Direction, ) -> impl Iterator<Item = (Port, Type)>
Iterator over all outgoing ports that have Value type, along with corresponding types.
Sourcefn in_value_types(
&self,
node: Self::Node,
) -> impl Iterator<Item = (IncomingPort, Type)>
fn in_value_types( &self, node: Self::Node, ) -> impl Iterator<Item = (IncomingPort, Type)>
Iterator over all incoming ports that have Value type, along with corresponding types.
Sourcefn out_value_types(
&self,
node: Self::Node,
) -> impl Iterator<Item = (OutgoingPort, Type)>
fn out_value_types( &self, node: Self::Node, ) -> impl Iterator<Item = (OutgoingPort, Type)>
Iterator over all incoming ports that have Value type, along with corresponding types.
Sourcefn extensions(&self) -> &ExtensionRegistry
fn extensions(&self) -> &ExtensionRegistry
Returns the set of extensions used by the HUGR.
This set may contain extensions that are no longer required by the HUGR.
Sourcefn validate(&self) -> Result<(), ValidationError>
fn validate(&self) -> Result<(), ValidationError>
Check the validity of the underlying HUGR.
This includes checking consistency of extension requirements between
connected nodes and between parents and children.
See HugrView::validate_no_extensions for a version that doesn’t check
extension requirements.
Sourcefn validate_no_extensions(&self) -> Result<(), ValidationError>
fn validate_no_extensions(&self) -> Result<(), ValidationError>
Check the validity of the underlying HUGR, but don’t check consistency of extension requirements between connected nodes or between parents and children.
For a more thorough check, use HugrView::validate.
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.