Skip to content

Commit

Permalink
feat: CustomOp::extension utility function (#951)
Browse files Browse the repository at this point in the history
Small utility function, both variants of a `CustomOp` expose their
extension already.
  • Loading branch information
aborgna-q authored Apr 18, 2024
1 parent b7df2ef commit 8cd3ee9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hugr/src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ impl CustomOp {
}
}

/// Returns the extension ID of this operation.
pub fn extension(&self) -> &ExtensionId {
match self {
Self::Opaque(op) => op.extension(),
Self::Extension(op) => op.def.extension(),
}
}

/// If the operation is an instance of [ExtensionOp], return a reference to it.
/// If the operation is opaque, return None.
pub fn as_extension_op(&self) -> Option<&ExtensionOp> {
Expand Down

0 comments on commit 8cd3ee9

Please sign in to comment.