Skip to content

Commit

Permalink
Move valid_node/valid_non_root into HugrView (no uses yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Sep 12, 2023
1 parent 9ebbe75 commit 1fea126
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
24 changes: 0 additions & 24 deletions src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,30 +312,6 @@ pub(crate) mod sealed {
/// Returns the Hugr at the base of a chain of views.
fn hugr_mut(&mut self) -> &mut Hugr;

/// Validates that a node is valid in the graph.
///
/// Returns a [`HugrError::InvalidNode`] otherwise.
#[inline]
fn valid_node(&self, node: Node) -> Result<(), HugrError> {
match self.contains_node(node) {
true => Ok(()),
false => Err(HugrError::InvalidNode(node)),
}
}

/// Validates that a node is a valid root descendant in the graph.
///
/// To include the root node use [`HugrMutInternals::valid_node`] instead.
///
/// Returns a [`HugrError::InvalidNode`] otherwise.
#[inline]
fn valid_non_root(&self, node: Node) -> Result<(), HugrError> {
match self.root() == node {
true => Err(HugrError::InvalidNode(node)),
false => self.valid_node(node),
}
}

/// Add a node to the graph, with the default conversion from OpType to NodeType
fn add_op(&mut self, op: impl Into<OpType>) -> Node {
self.hugr_mut().add_op(op)
Expand Down
26 changes: 25 additions & 1 deletion src/hugr/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use itertools::{Itertools, MapInto};
use portgraph::dot::{DotFormat, EdgeStyle, NodeStyle, PortStyle};
use portgraph::{multiportgraph, LinkView, MultiPortGraph, PortView};

use super::{Hugr, NodeMetadata, NodeType};
use super::{Hugr, HugrError, NodeMetadata, NodeType};
use crate::ops::handle::NodeHandle;
use crate::ops::{FuncDecl, FuncDefn, OpName, OpTag, OpType, DFG};
use crate::types::{EdgeKind, FunctionType};
Expand Down Expand Up @@ -80,6 +80,30 @@ pub trait HugrView: sealed::HugrInternals {
/// Returns whether the node exists.
fn contains_node(&self, node: Node) -> bool;

/// Validates that a node is valid in the graph.
///
/// Returns a [`HugrError::InvalidNode`] otherwise.
#[inline]
fn valid_node(&self, node: Node) -> Result<(), HugrError> {
match self.contains_node(node) {
true => Ok(()),
false => Err(HugrError::InvalidNode(node)),
}
}

/// Validates that a node is a valid root descendant in the graph.
///
/// To include the root node use [`HugrMutInternals::valid_node`] instead.
///
/// Returns a [`HugrError::InvalidNode`] otherwise.
#[inline]
fn valid_non_root(&self, node: Node) -> Result<(), HugrError> {
match self.root() == node {
true => Err(HugrError::InvalidNode(node)),
false => self.valid_node(node),
}
}

/// Returns the parent of a node.
fn get_parent(&self, node: Node) -> Option<Node>;

Expand Down

0 comments on commit 1fea126

Please sign in to comment.