pub trait MakeOpDef {
// Required methods
fn opdef_id(&self) -> OpName;
fn from_def(op_def: &OpDef) -> Result<Self, OpLoadError>
where Self: Sized;
fn extension(&self) -> ExtensionId;
fn extension_ref(&self) -> Weak<Extension>;
fn init_signature(&self, extension_ref: &Weak<Extension>) -> SignatureFunc;
// Provided methods
fn signature(&self) -> SignatureFunc { ... }
fn description(&self) -> String { ... }
fn post_opdef(&self, _def: &mut OpDef) { ... }
fn add_to_extension(
&self,
extension: &mut Extension,
extension_ref: &Weak<Extension>,
) -> Result<(), ExtensionBuildError> { ... }
fn load_all_ops(
extension: &mut Extension,
extension_ref: &Weak<Extension>,
) -> Result<(), ExtensionBuildError>
where Self: IntoEnumIterator { ... }
fn from_op(ext_op: &ExtensionOp) -> Result<Self, OpLoadError>
where Self: Sized + FromStr { ... }
}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.
MakeExtensionOp has a blanket impl for types that impl MakeOpDef.
Required Methods§
Sourcefn opdef_id(&self) -> OpName
fn opdef_id(&self) -> OpName
The OpDef::name which will be used when Self is added to an Extension
or when Self is loaded from an OpDef.
This identifer must be unique within the extension with which the
OpDef is registered. An ExtensionOp instantiating this OpDef will
report self.opdef_id() as its ExtensionOp::unqualified_id.
MakeExtensionOp::op_id must match this function.
Sourcefn from_def(op_def: &OpDef) -> Result<Self, OpLoadError>where
Self: Sized,
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.
Sourcefn extension(&self) -> ExtensionId
fn extension(&self) -> ExtensionId
The ID of the extension this operation is defined in.
Sourcefn extension_ref(&self) -> Weak<Extension>
fn extension_ref(&self) -> Weak<Extension>
Returns a weak reference to the extension this operation is defined in.
Sourcefn init_signature(&self, extension_ref: &Weak<Extension>) -> SignatureFunc
fn init_signature(&self, extension_ref: &Weak<Extension>) -> SignatureFunc
Compute the signature of the operation while the extension definition is being built.
Requires a Weak reference to the extension defining the operation.
This method is intended to be used inside the closure passed to Extension::new_arc,
and it is normally internally called by MakeOpDef::add_to_extension.
Provided Methods§
Sourcefn signature(&self) -> SignatureFunc
fn signature(&self) -> SignatureFunc
Return the signature (polymorphic function type) of the operation.
Sourcefn description(&self) -> String
fn description(&self) -> String
Description of the operation. By default, the same as self.opdef_id().
Sourcefn post_opdef(&self, _def: &mut OpDef)
fn post_opdef(&self, _def: &mut OpDef)
Edit the opdef before finalising. By default does nothing.
Sourcefn add_to_extension(
&self,
extension: &mut Extension,
extension_ref: &Weak<Extension>,
) -> Result<(), ExtensionBuildError>
fn add_to_extension( &self, extension: &mut Extension, extension_ref: &Weak<Extension>, ) -> Result<(), ExtensionBuildError>
Add an operation implemented as an MakeOpDef, which can provide the data
required to define an OpDef, to an extension.
Requires a Weak reference to the extension defining the operation.
This method is intended to be used inside the closure passed to Extension::new_arc.
Sourcefn load_all_ops(
extension: &mut Extension,
extension_ref: &Weak<Extension>,
) -> Result<(), ExtensionBuildError>where
Self: IntoEnumIterator,
fn load_all_ops(
extension: &mut Extension,
extension_ref: &Weak<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.
Requires a Weak reference to the extension defining the operation.
This method is intended to be used inside the closure passed to Extension::new_arc.
Sourcefn from_op(ext_op: &ExtensionOp) -> Result<Self, OpLoadError>
fn from_op(ext_op: &ExtensionOp) -> Result<Self, OpLoadError>
If the definition can be loaded from a string, load from an ExtensionOp.