diff --git a/hugr/src/ops/leaf.rs b/hugr/src/ops/leaf.rs index 178ded03a..b39d73324 100644 --- a/hugr/src/ops/leaf.rs +++ b/hugr/src/ops/leaf.rs @@ -18,6 +18,13 @@ pub struct Noop { pub ty: Type, } +impl Noop { + /// Create a new Noop operation. + pub fn new(ty: Type) -> Self { + Self { ty } + } +} + impl Default for Noop { fn default() -> Self { Self { ty: Type::UNIT } @@ -32,6 +39,13 @@ pub struct MakeTuple { pub tys: TypeRow, } +impl MakeTuple { + /// Create a new MakeTuple operation. + pub fn new(tys: TypeRow) -> Self { + Self { tys } + } +} + /// An operation that unpacks a tuple into its components. #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[non_exhaustive] @@ -40,6 +54,13 @@ pub struct UnpackTuple { pub tys: TypeRow, } +impl UnpackTuple { + /// Create a new UnpackTuple operation. + pub fn new(tys: TypeRow) -> Self { + Self { tys } + } +} + /// An operation that creates a tagged sum value from one of its variants. #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[non_exhaustive] @@ -50,6 +71,13 @@ pub struct Tag { pub variants: Vec, } +impl Tag { + /// Create a new Tag operation. + pub fn new(tag: usize, variants: Vec) -> Self { + Self { tag, variants } + } +} + /// A node which adds a extension req to the types of the wires it is passed /// It has no effect on the values passed along the edge #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] @@ -61,6 +89,16 @@ pub struct Lift { pub new_extension: ExtensionId, } +impl Lift { + /// Create a new Lift operation. + pub fn new(type_row: TypeRow, new_extension: ExtensionId) -> Self { + Self { + type_row, + new_extension, + } + } +} + impl_op_name!(Noop); impl_op_name!(MakeTuple); impl_op_name!(UnpackTuple);