Trait hugr_core::extension::simple_op::MakeOpDef

source ·
pub trait MakeOpDef: NamedOp {
    // Required methods
    fn from_def(op_def: &OpDef) -> Result<Self, OpLoadError>
       where Self: Sized;
    fn signature(&self) -> SignatureFunc;

    // Provided methods
    fn description(&self) -> String { ... }
    fn post_opdef(&self, _def: &mut OpDef) { ... }
    fn add_to_extension(
        &self,
        extension: &mut Extension
    ) -> Result<(), ExtensionBuildError> { ... }
    fn load_all_ops(
        extension: &mut Extension
    ) -> Result<(), ExtensionBuildError>
       where Self: IntoEnumIterator { ... }
}
Expand description

Traits implemented by types which can add themselves to Extensions as OpDefs or load themselves from an OpDef. Particularly useful with C-style enums that implement strum::IntoEnumIterator, as then all definitions can be added to an extension at once.

Required Methods§

source

fn from_def(op_def: &OpDef) -> Result<Self, OpLoadError>
where Self: Sized,

Try to load one of the operations of this set from an OpDef.

source

fn signature(&self) -> SignatureFunc

Return the signature (polymorphic function type) of the operation.

Provided Methods§

source

fn description(&self) -> String

Description of the operation. By default, the same as self.name().

source

fn post_opdef(&self, _def: &mut OpDef)

Edit the opdef before finalising. By default does nothing.

source

fn add_to_extension( &self, extension: &mut Extension ) -> Result<(), ExtensionBuildError>

Add an operation implemented as an MakeOpDef, which can provide the data required to define an OpDef, to an extension.

source

fn load_all_ops(extension: &mut Extension) -> Result<(), ExtensionBuildError>
where Self: IntoEnumIterator,

Load all variants of an enum of op definitions in to an extension as op defs. See strum::IntoEnumIterator.

Implementors§