pub trait IntoPyNativeFn<Kind>: Sized + PyThreadingConstraint + 'static {
    const STATIC_FUNC: &'static PyNativeFn = _;

    // 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>

Provided Associated Constants§

source

const STATIC_FUNC: &'static PyNativeFn = _

Equivalent to into_func(), but accessible as a constant. This is only valid if this function is zero-sized, i.e. that std::mem::size_of::<F>() == 0. If it isn’t, use of this constant will raise a compile error.

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

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