pub trait PyFunctionArgument<'a, 'holder, 'py, const IMPLEMENTS_FROMPYOBJECT: bool>: Sized + Sealed<IMPLEMENTS_FROMPYOBJECT> {
type Holder: FunctionArgumentHolder;
type Error: Into<PyErr>;
const INPUT_TYPE: PyStaticExpr;
// Required method
fn extract(
obj: Borrowed<'a, 'py, PyAny>,
holder: &'holder mut Self::Holder,
) -> Result<Self, Self::Error>;
}Expand description
A trait which is used to help PyO3 macros extract function arguments.
#[pyclass] structs need to extract as PyRef<T> and PyRefMut<T>
wrappers rather than extracting &T and &mut T directly. The Holder type is used
to hold these temporary wrappers - the way the macro is constructed, these wrappers
will be dropped as soon as the pyfunction call ends.
There exists a trivial blanket implementation for T: FromPyObject with Holder = ().
The const generic arg IMPLEMENTS_FROMPYOBJECT allows for const generic specialization of
some additional types which don’t implement FromPyObject, such as &T for #[pyclass] types.
All types should only implement this trait once; either by the FromPyObject blanket or one
of the specialized implementations which needs a Holder.
Required Associated Constants§
Sourceconst INPUT_TYPE: PyStaticExpr
Available on crate feature experimental-inspect only.
const INPUT_TYPE: PyStaticExpr
experimental-inspect only.Provides the type hint information for which Python types are allowed.
Required Associated Types§
Required Methods§
fn extract( obj: Borrowed<'a, 'py, PyAny>, holder: &'holder mut Self::Holder, ) -> Result<Self, Self::Error>
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.
Implementations on Foreign Types§
Source§impl<'a, 'holder, 'py, T> PyFunctionArgument<'a, 'holder, 'py, false> for Option<T>where
T: PyFunctionArgument<'a, 'holder, 'py, false>,
Allow Option<T> to be a function argument also for types which don’t implement FromPyObject
impl<'a, 'holder, 'py, T> PyFunctionArgument<'a, 'holder, 'py, false> for Option<T>where
T: PyFunctionArgument<'a, 'holder, 'py, false>,
Allow Option<T> to be a function argument also for types which don’t implement FromPyObject
Source§const INPUT_TYPE: PyStaticExpr
const INPUT_TYPE: PyStaticExpr
experimental-inspect only.