From a866bb575c1d31ffe857a222ad3e7c2e7a70448f Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Wed, 11 Dec 2024 15:43:33 +0000 Subject: [PATCH] feat: add `is_` variant methods to `EdgeKind` (#1768) Closes #1767 --- hugr-core/src/types.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hugr-core/src/types.rs b/hugr-core/src/types.rs index 54ba5dc13..6fcb292b6 100644 --- a/hugr-core/src/types.rs +++ b/hugr-core/src/types.rs @@ -76,6 +76,46 @@ impl EdgeKind { pub fn is_static(&self) -> bool { matches!(self, EdgeKind::Const(_) | EdgeKind::Function(_)) } + + /// Returns `true` if the edge kind is [`ControlFlow`]. + /// + /// [`ControlFlow`]: EdgeKind::ControlFlow + #[must_use] + pub fn is_control_flow(&self) -> bool { + matches!(self, Self::ControlFlow) + } + + /// Returns `true` if the edge kind is [`Value`]. + /// + /// [`Value`]: EdgeKind::Value + #[must_use] + pub fn is_value(&self) -> bool { + matches!(self, Self::Value(..)) + } + + /// Returns `true` if the edge kind is [`Const`]. + /// + /// [`Const`]: EdgeKind::Const + #[must_use] + pub fn is_const(&self) -> bool { + matches!(self, Self::Const(..)) + } + + /// Returns `true` if the edge kind is [`Function`]. + /// + /// [`Function`]: EdgeKind::Function + #[must_use] + pub fn is_function(&self) -> bool { + matches!(self, Self::Function(..)) + } + + /// Returns `true` if the edge kind is [`StateOrder`]. + /// + /// [`StateOrder`]: EdgeKind::StateOrder + #[must_use] + pub fn is_state_order(&self) -> bool { + matches!(self, Self::StateOrder) + } } #[derive(