diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 14f7b6e7b1..2986c628c2 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -1379,6 +1379,20 @@ where } } +// For functions that accept no arguments. Implemented explicitly instead of via +// macro below to avoid unused warnings. +impl FromArgs for () { + fn from_args( + _vm: &mut VirtualMachine, + _args: &mut iter::Peekable, + ) -> Result + where + I: Iterator, + { + Ok(()) + } +} + // A tuple of types that each implement `FromArgs` represents a sequence of // arguments that can be bound and passed to a built-in function. // @@ -1465,25 +1479,26 @@ impl IntoPyNativeFunc for PyNativeFunc { // // Note that this could be done without a macro - it is simply to avoid repetition. macro_rules! into_py_native_func_tuple { - ($(($n:tt, $T:ident)),+) => { - impl IntoPyNativeFunc<($($T,)+), R> for F + ($(($n:tt, $T:ident)),*) => { + impl IntoPyNativeFunc<($($T,)*), R> for F where - F: Fn($($T,)+ &mut VirtualMachine) -> R + 'static, - $($T: FromArgs,)+ - ($($T,)+): FromArgs, + F: Fn($($T,)* &mut VirtualMachine) -> R + 'static, + $($T: FromArgs,)* + ($($T,)*): FromArgs, R: IntoPyObject, { fn into_func(self) -> PyNativeFunc { Box::new(move |vm, args| { - let ($($n,)+) = args.bind::<($($T,)+)>(vm)?; + let ($($n,)*) = args.bind::<($($T,)*)>(vm)?; - (self)($($n,)+ vm).into_pyobject(&vm.ctx) + (self)($($n,)* vm).into_pyobject(&vm.ctx) }) } } }; } +into_py_native_func_tuple!(); into_py_native_func_tuple!((a, A)); into_py_native_func_tuple!((a, A), (b, B)); into_py_native_func_tuple!((a, A), (b, B), (c, C));