Skip to content

Commit d8c394a

Browse files
sunny-gfilmor
authored andcommitted
cleanup
1 parent 26ea227 commit d8c394a

File tree

1 file changed

+41
-51
lines changed

1 file changed

+41
-51
lines changed

rustler/src/schedule.rs

Lines changed: 41 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum Schedule<N: crate::Nif, T, A = (), B = (), C = (), D = (), E = (), F =
5858
Return(T),
5959
/// Single- and multiple-argument variants that should reflect the scheduled
6060
/// NIF's function signature.
61-
Continue(PhantomData<N>, SchedulerFlags, A),
61+
Continue1(PhantomData<N>, SchedulerFlags, A),
6262
Continue2(PhantomData<N>, SchedulerFlags, A, B),
6363
Continue3(PhantomData<N>, SchedulerFlags, A, B, C),
6464
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 =
6767
Continue7(PhantomData<N>, SchedulerFlags, A, B, C, D, E, F, G),
6868
}
6969

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,)*);)*) => {
7272
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)]
7474
#[inline]
7575
pub fn $func_name(flags: SchedulerFlags, $($arg: $ty),*) -> Self {
7676
Self::$variant(PhantomData, flags, $($arg),*)
77-
}
77+
})*
7878
}
7979

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> {
8181
#[allow(clippy::many_single_char_names)]
8282
#[inline]
8383
fn from((flags, $($arg),*): (SchedulerFlags, $($ty),*)) -> Self {
8484
Self::$func_name(flags, $($arg),*)
8585
}
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+
})*
9787

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+
},)*
119111
}
120-
)
112+
}
121113
}
114+
};
115+
}
122116

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,);
135125
}

0 commit comments

Comments
 (0)