Allow functions that don't take any args
@@ -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<I>(
+ _vm: &mut VirtualMachine,
+ _args: &mut iter::Peekable<I>,
+ ) -> Result<Self, ArgumentError>
+ where
+ I: Iterator<Item = PyArg>,
+ {
+ 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<PyFuncArgs, PyResult> 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<F, $($T,)+ R> IntoPyNativeFunc<($($T,)+), R> for F
+ ($(($n:tt, $T:ident)),*) => {
+ impl<F, $($T,)* R> 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));
