pub trait MakeOpDef: NamedOp {
// Required methods
fn from_def(op_def: &OpDef) -> Result<Self, OpLoadError>
where Self: Sized;
fn signature(&self) -> SignatureFunc;
fn extension(&self) -> ExtensionId;
// 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 { ... }
fn from_op(custom_op: &CustomOp) -> 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 signature(&self) -> SignatureFunc
fn signature(&self) -> SignatureFunc
Return the signature (polymorphic function type) of the operation.
sourcefn extension(&self) -> ExtensionId
fn extension(&self) -> ExtensionId
The ID of the extension this operation is defined in.
Provided Methods§
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,
) -> Result<(), ExtensionBuildError>
fn add_to_extension( &self, extension: &mut Extension, ) -> Result<(), ExtensionBuildError>
sourcefn load_all_ops(extension: &mut Extension) -> Result<(), ExtensionBuildError>where
Self: IntoEnumIterator,
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.
sourcefn from_op(custom_op: &CustomOp) -> Result<Self, OpLoadError>
fn from_op(custom_op: &CustomOp) -> Result<Self, OpLoadError>
If the definition can be loaded from a string, load from an ExtensionOp.