Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ExternalOp::args getter #276

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ pub enum ExternalOp {
Opaque(OpaqueOp),
}

impl ExternalOp {
/// Return the argument values for this operation.
pub fn args(&self) -> &[TypeArg] {
match self {
Self::Opaque(op) => op.args(),
Self::Resource(op) => op.args(),
}
}
}

impl From<ExternalOp> for OpaqueOp {
fn from(value: ExternalOp) -> Self {
match value {
Expand Down Expand Up @@ -106,6 +116,11 @@ impl ResourceOp {
signature,
})
}

/// Return the argument values for this operation.
pub fn args(&self) -> &[TypeArg] {
&self.args
}
}

impl From<ResourceOp> for OpaqueOp {
Expand Down Expand Up @@ -169,6 +184,11 @@ impl OpaqueOp {
signature,
}
}

/// Return the argument values for this operation.
pub fn args(&self) -> &[TypeArg] {
&self.args
}
}

/// Resolve serialized names of operations into concrete implementation (OpDefs) where possible
Expand Down Expand Up @@ -225,3 +245,25 @@ pub enum CustomOpError {
#[error("Resolved {0} to a concrete implementation which computed a conflicting signature: {1:?} vs stored {2:?}")]
SignatureMismatch(String, Signature, Signature),
}

#[cfg(test)]
mod test {
use crate::types::ClassicType;

use super::*;

#[test]
fn new_opaque_op() {
let op = OpaqueOp::new(
"res".into(),
"op",
"desc".into(),
vec![TypeArg::ClassicType(ClassicType::F64)],
None,
);
let op: ExternalOp = op.into();
assert_eq!(op.name(), "res.op");
assert_eq!(op.description(), "desc");
assert_eq!(op.args(), &[TypeArg::ClassicType(ClassicType::F64)]);
}
}