pub trait IntoPyNativeFn<Kind>:
Sized
+ PyThreadingConstraint
+ 'static {
// Required method
fn call(&self, vm: &VirtualMachine, args: FuncArgs) -> PyResult;
// Provided method
fn into_func(self) -> impl 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§
fn call(&self, vm: &VirtualMachine, args: FuncArgs) -> PyResult
Provided Methods§
Sourcefn into_func(self) -> impl PyNativeFn
fn into_func(self) -> impl 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.