pub trait MakeOpDef: NamedOp {
// Required methods
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 Extension
s as
OpDef
s 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§
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.name()
.
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.