@@ -30,9 +30,18 @@ pub enum OpLoadError {
3030///
3131/// Particularly useful with C-style enums that implement [strum::IntoEnumIterator],
3232/// as then all definitions can be added to an extension at once.
33+ ///
34+ /// [MakeExtensionOp] has a blanket impl for types that impl [MakeOpDef].
3335pub trait MakeOpDef {
34- /// TODO docs
35- fn opdef_name ( & self ) -> OpName ;
36+ /// The [OpDef::name] which will be used when `Self` is added to an [Extension]
37+ /// or when `Self` is loaded from an [OpDef].
38+ ///
39+ /// This identifer must be unique within the extension with which the
40+ /// [OpDef] is registered. An [ExtensionOp] instantiating this [OpDef] will
41+ /// report `self.opdef_id()` as its [ExtensionOp::unqualified_id].
42+ ///
43+ /// [MakeExtensionOp::op_id] must match this function.
44+ fn opdef_id ( & self ) -> OpName ;
3645
3746 /// Try to load one of the operations of this set from an [OpDef].
3847 fn from_def ( op_def : & OpDef ) -> Result < Self , OpLoadError >
@@ -57,9 +66,9 @@ pub trait MakeOpDef {
5766 self . init_signature ( & self . extension_ref ( ) )
5867 }
5968
60- /// Description of the operation. By default, the same as `self.name ()`.
69+ /// Description of the operation. By default, the same as `self.opdef_id ()`.
6170 fn description ( & self ) -> String {
62- self . opdef_name ( ) . to_string ( )
71+ self . opdef_id ( ) . to_string ( )
6372 }
6473
6574 /// Edit the opdef before finalising. By default does nothing.
@@ -76,7 +85,7 @@ pub trait MakeOpDef {
7685 extension_ref : & Weak < Extension > ,
7786 ) -> Result < ( ) , ExtensionBuildError > {
7887 let def = extension. add_op (
79- self . opdef_name ( ) ,
88+ self . opdef_id ( ) ,
8089 self . description ( ) ,
8190 self . init_signature ( extension_ref) ,
8291 extension_ref,
@@ -140,8 +149,12 @@ pub trait HasDef: MakeExtensionOp {
140149/// Traits implemented by types which can be loaded from [`ExtensionOp`]s,
141150/// i.e. concrete instances of [`OpDef`]s, with defined type arguments.
142151pub trait MakeExtensionOp {
143- /// The name of the operation
144- fn name ( & self ) -> OpName ;
152+ /// The [OpDef::name] of [ExtensionOp]s from which `Self` can be loaded.
153+ ///
154+ /// This identifer must be unique within the extension with which the
155+ /// [OpDef] is registered. An [ExtensionOp] instantiating this [OpDef] will
156+ /// report `self.opdef_id()` as its [ExtensionOp::unqualified_id].
157+ fn op_id ( & self ) -> OpName ;
145158
146159 /// Try to load one of the operations of this set from an [OpDef].
147160 fn from_extension_op ( ext_op : & ExtensionOp ) -> Result < Self , OpLoadError >
@@ -180,8 +193,8 @@ pub trait MakeExtensionOp {
180193
181194/// Blanket implementation for non-polymorphic operations - [OpDef]s with no type parameters.
182195impl < T : MakeOpDef > MakeExtensionOp for T {
183- fn name ( & self ) -> OpName {
184- < Self as MakeOpDef > :: opdef_name ( self )
196+ fn op_id ( & self ) -> OpName {
197+ self . opdef_id ( )
185198 }
186199
187200 #[ inline]
@@ -239,7 +252,7 @@ impl<T: MakeExtensionOp> RegisteredOp<T> {
239252 /// Generate an [OpType].
240253 pub fn to_extension_op ( & self ) -> Option < ExtensionOp > {
241254 ExtensionOp :: new (
242- self . extension . upgrade ( ) ?. get_op ( & self . name ( ) ) ?. clone ( ) ,
255+ self . extension . upgrade ( ) ?. get_op ( & self . op_id ( ) ) ?. clone ( ) ,
243256 self . type_args ( ) ,
244257 )
245258 . ok ( )
@@ -248,7 +261,7 @@ impl<T: MakeExtensionOp> RegisteredOp<T> {
248261 delegate ! {
249262 to self . op {
250263 /// Name of the operation - derived from strum serialization.
251- pub fn name ( & self ) -> OpName ;
264+ pub fn op_id ( & self ) -> OpName ;
252265 /// Any type args which define this operation. Default is no type arguments.
253266 pub fn type_args( & self ) -> Vec <TypeArg >;
254267 }
@@ -306,8 +319,8 @@ mod test {
306319 }
307320
308321 impl MakeOpDef for DummyEnum {
309- fn opdef_name ( & self ) -> OpName {
310- <& Self as Into < & ' static str > > :: into ( self ) . into ( )
322+ fn opdef_id ( & self ) -> OpName {
323+ <& ' static str >:: from ( self ) . into ( )
311324 }
312325
313326 fn init_signature ( & self , _extension_ref : & Weak < Extension > ) -> SignatureFunc {
@@ -366,7 +379,7 @@ mod test {
366379 let o = DummyEnum :: Dumb ;
367380
368381 assert_eq ! (
369- DummyEnum :: from_def( EXT . get_op( & o. opdef_name ( ) ) . unwrap( ) ) . unwrap( ) ,
382+ DummyEnum :: from_def( EXT . get_op( & o. opdef_id ( ) ) . unwrap( ) ) . unwrap( ) ,
370383 o
371384 ) ;
372385
0 commit comments