Trait PyFunctionArgument

Source
pub trait PyFunctionArgument<'a, 'py, const IS_OPTION: bool>: Sized + 'a {
    type Holder: FunctionArgumentHolder;

    const INPUT_TYPE: &'static str;

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

Source

const INPUT_TYPE: &'static str

Available on crate feature experimental-inspect only.

Provides the type hint information for which Python types are allowed.

Required Associated Types§

Required Methods§

Source

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

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, 'py, T> PyFunctionArgument<'a, 'py, true> for Option<T>
where T: PyFunctionArgument<'a, 'py, false>,

Source§

const INPUT_TYPE: &'static str = "typing.Any | None"

Available on crate feature experimental-inspect only.
Source§

type Holder = <T as PyFunctionArgument<'a, 'py, false>>::Holder

Source§

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

Implementors§

Source§

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

Available on crate feature experimental-async only.
Source§

const INPUT_TYPE: &'static str = "Coroutine"

Source§

type Holder = Option<PyRef<'py, Coroutine>>

Source§

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

Available on crate feature experimental-async only.
Source§

const INPUT_TYPE: &'static str = "Coroutine"

Source§

type Holder = Option<PyRefMut<'py, Coroutine>>

Source§

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

Source§

const INPUT_TYPE: &'static str = T::PYTHON_TYPE

Source§

type Holder = ()

Source§

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

Source§

const INPUT_TYPE: &'static str = T::INPUT_TYPE

Source§

type Holder = ()

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