pub trait IntoPyNativeFn<Kind>: Sized + PyThreadingConstraint + 'static {
    // Required method
    fn call(&self, vm: &VirtualMachine, args: FuncArgs) -> PyResult;

    // Provided method
    fn into_func(self) -> &'static PyNativeFn { ... }
}
Expand description

Implemented by types that are or can generate built-in functions.

This trait is implemented by any function that matches the pattern:

Fn([&self,] [T where T: FromArgs, ...] [, vm: &VirtualMachine])

For example, anything from Fn() to Fn(vm: &VirtualMachine) -> u32 to Fn(PyIntRef, PyIntRef) -> String to Fn(&self, PyStrRef, FooOptions, vm: &VirtualMachine) -> PyResult<PyInt> is IntoPyNativeFn. If you do want a really general function signature, e.g. to forward the args to another function, you can define a function like Fn(FuncArgs [, &VirtualMachine]) -> ...

Note that the Kind type parameter is meaningless and should be considered an implementation detail; if you need to use IntoPyNativeFn as a trait bound just pass an unconstrained generic type, e.g. fn foo<F, FKind>(f: F) where F: IntoPyNativeFn<FKind>

Required Methods§

source

fn call(&self, vm: &VirtualMachine, args: FuncArgs) -> PyResult

Provided Methods§

source

fn into_func(self) -> &'static PyNativeFn

IntoPyNativeFn::into_func() generates a PyNativeFn that performs the appropriate type and arity checking, any requested conversions, and then if successful calls the function with the extracted parameters.

Implementors§

source§

impl<F, T, R, VM> IntoPyNativeFn<(T, R, VM)> for Fwhere F: PyNativeFnInternal<T, R, VM>,