Trait pyo3::impl_::extract_argument::PyFunctionArgument

source ·
pub trait PyFunctionArgument<'a, 'py>: Sized + 'a {
    type Holder: FunctionArgumentHolder;

    // Required method
    fn extract(
        obj: &'a Bound<'py, PyAny>,
        holder: &'a mut Self::Holder
    ) -> PyResult<Self>;
}
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 = ().

Required Associated Types§

Required Methods§

source

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder ) -> PyResult<Self>

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, 'py, T> PyFunctionArgument<'a, 'py> for Option<&'a Bound<'py, T>>
where T: PyTypeCheck + 'py,

§

type Holder = ()

source§

fn extract(obj: &'a Bound<'py, PyAny>, _: &'a mut ()) -> PyResult<Self>

Implementors§

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a Coroutine

Available on crate feature experimental-async only.
source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut Coroutine

Available on crate feature experimental-async only.
source§

impl<'a, 'py, T> PyFunctionArgument<'a, 'py> for &'a Bound<'py, T>
where T: PyTypeCheck + 'py,

source§

impl<'a, 'py, T> PyFunctionArgument<'a, 'py> for T
where T: FromPyObjectBound<'a, 'py> + 'a,

§

type Holder = ()

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here