@@ -58,7 +58,7 @@ pub enum Schedule<N: crate::Nif, T, A = (), B = (), C = (), D = (), E = (), F =
58
58
Return ( T ) ,
59
59
/// Single- and multiple-argument variants that should reflect the scheduled
60
60
/// NIF's function signature.
61
- Continue ( PhantomData < N > , SchedulerFlags , A ) ,
61
+ Continue1 ( PhantomData < N > , SchedulerFlags , A ) ,
62
62
Continue2 ( PhantomData < N > , SchedulerFlags , A , B ) ,
63
63
Continue3 ( PhantomData < N > , SchedulerFlags , A , B , C ) ,
64
64
Continue4 ( PhantomData < N > , SchedulerFlags , A , B , C , D ) ,
@@ -67,69 +67,59 @@ pub enum Schedule<N: crate::Nif, T, A = (), B = (), C = (), D = (), E = (), F =
67
67
Continue7 ( PhantomData < N > , SchedulerFlags , A , B , C , D , E , F , G ) ,
68
68
}
69
69
70
- macro_rules! impl_funcs {
71
- ( $variant: ident $func_name: ident( $( $arg: ident : $ty: ty, ) * ) ) => {
70
+ macro_rules! impls {
71
+ ( $( $ variant: ident $func_name: ident( $( $arg: ident : $ty: ty, ) * ) ; ) * ) => {
72
72
impl <N : crate :: Nif , T , A , B , C , D , E , F , G > Schedule <N , T , A , B , C , D , E , F , G > {
73
- #[ allow( clippy:: many_single_char_names) ]
73
+ $ ( #[ allow( clippy:: many_single_char_names) ]
74
74
#[ inline]
75
75
pub fn $func_name( flags: SchedulerFlags , $( $arg: $ty) ,* ) -> Self {
76
76
Self :: $variant( PhantomData , flags, $( $arg) ,* )
77
- }
77
+ } ) *
78
78
}
79
79
80
- impl <N : crate :: Nif , T , A , B , C , D , E , F , G > From <( SchedulerFlags , $( $ty) ,* ) > for Schedule <N , T , A , B , C , D , E , F , G > {
80
+ $ ( impl <N : crate :: Nif , T , A , B , C , D , E , F , G > From <( SchedulerFlags , $( $ty) ,* ) > for Schedule <N , T , A , B , C , D , E , F , G > {
81
81
#[ allow( clippy:: many_single_char_names) ]
82
82
#[ inline]
83
83
fn from( ( flags, $( $arg) ,* ) : ( SchedulerFlags , $( $ty) ,* ) ) -> Self {
84
84
Self :: $func_name( flags, $( $arg) ,* )
85
85
}
86
- }
87
- } ;
88
- }
89
-
90
- impl_funcs ! { Continue continue1( a: A , ) }
91
- impl_funcs ! { Continue2 continue2( a: A , b: B , ) }
92
- impl_funcs ! { Continue3 continue3( a: A , b: B , c: C , ) }
93
- impl_funcs ! { Continue4 continue4( a: A , b: B , c: C , d: D , ) }
94
- impl_funcs ! { Continue5 continue5( a: A , b: B , c: C , d: D , e: E , ) }
95
- impl_funcs ! { Continue6 continue6( a: A , b: B , c: C , d: D , e: E , f: F , ) }
96
- impl_funcs ! { Continue7 continue7( a: A , b: B , c: C , d: D , e: E , f: F , g: G , ) }
86
+ } ) *
97
87
98
- unsafe impl < N , T , A , B , C , D , E , F , G > NifReturnable for Schedule < N , T , A , B , C , D , E , F , G >
99
- where
100
- N : crate :: Nif ,
101
- T : crate :: Encoder ,
102
- A : crate :: Encoder ,
103
- B : crate :: Encoder ,
104
- C : crate :: Encoder ,
105
- D : crate :: Encoder ,
106
- E : crate :: Encoder ,
107
- F : crate :: Encoder ,
108
- G : crate :: Encoder ,
109
- {
110
- #[ inline]
111
- unsafe fn into_returned ( self , env : Env ) -> NifReturned {
112
- macro_rules! branch {
113
- ( $flags: expr, $( $arg: tt) ,* ) => (
114
- NifReturned :: Reschedule {
115
- fun_name: CStr :: from_ptr( N :: NAME as * const c_char) . into( ) ,
116
- flags: $flags,
117
- fun: N :: RAW_FUNC ,
118
- args: vec![ $( $arg. encode( env) . as_c_arg( ) ) ,* ] ,
88
+ unsafe impl <N , T , A , B , C , D , E , F , G > NifReturnable for Schedule <N , T , A , B , C , D , E , F , G >
89
+ where
90
+ N : crate :: Nif ,
91
+ T : crate :: Encoder ,
92
+ A : crate :: Encoder ,
93
+ B : crate :: Encoder ,
94
+ C : crate :: Encoder ,
95
+ D : crate :: Encoder ,
96
+ E : crate :: Encoder ,
97
+ F : crate :: Encoder ,
98
+ G : crate :: Encoder ,
99
+ {
100
+ #[ inline]
101
+ unsafe fn into_returned( self , env: Env ) -> NifReturned {
102
+ #[ allow( clippy:: many_single_char_names) ]
103
+ match self {
104
+ Self :: Return ( res) => NifReturned :: Term ( res. encode( env) . as_c_arg( ) ) ,
105
+ $( Self :: $variant( _, flags, $( $arg) ,* ) => NifReturned :: Reschedule {
106
+ fun_name: CStr :: from_ptr( N :: NAME as * const c_char) . into( ) ,
107
+ flags,
108
+ fun: N :: RAW_FUNC ,
109
+ args: vec![ $( $arg. encode( env) . as_c_arg( ) ) ,* ] ,
110
+ } , ) *
119
111
}
120
- )
112
+ }
121
113
}
114
+ } ;
115
+ }
122
116
123
- #[ allow( clippy:: many_single_char_names) ]
124
- match self {
125
- Self :: Return ( res) => NifReturned :: Term ( res. encode ( env) . as_c_arg ( ) ) ,
126
- Self :: Continue ( _, flags, a) => branch ! ( flags, a) ,
127
- Self :: Continue2 ( _, flags, a, b) => branch ! ( flags, a, b) ,
128
- Self :: Continue3 ( _, flags, a, b, c) => branch ! ( flags, a, b, c) ,
129
- Self :: Continue4 ( _, flags, a, b, c, d) => branch ! ( flags, a, b, c, d) ,
130
- Self :: Continue5 ( _, flags, a, b, c, d, e) => branch ! ( flags, a, b, c, d, e) ,
131
- Self :: Continue6 ( _, flags, a, b, c, d, e, f) => branch ! ( flags, a, b, c, d, e, f) ,
132
- Self :: Continue7 ( _, flags, a, b, c, d, e, f, g) => branch ! ( flags, a, b, c, d, e, f, g) ,
133
- }
134
- }
117
+ impls ! {
118
+ Continue1 continue1( a: A , ) ;
119
+ Continue2 continue2( a: A , b: B , ) ;
120
+ Continue3 continue3( a: A , b: B , c: C , ) ;
121
+ Continue4 continue4( a: A , b: B , c: C , d: D , ) ;
122
+ Continue5 continue5( a: A , b: B , c: C , d: D , e: E , ) ;
123
+ Continue6 continue6( a: A , b: B , c: C , d: D , e: E , f: F , ) ;
124
+ Continue7 continue7( a: A , b: B , c: C , d: D , e: E , f: F , g: G , ) ;
135
125
}
0 commit comments