pyo3::conversion

Trait FromPyObjectBound

Source
pub trait FromPyObjectBound<'a, 'py>: Sized + Sealed {
    // Required method
    fn from_py_object_bound(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self>;
}
Expand description

Expected form of FromPyObject to be used in a future PyO3 release.

The difference between this and FromPyObject is that this trait takes an additional lifetime 'a, which is the lifetime of the input Bound.

This allows implementations for &'a str and &'a [u8], which could not be expressed by the existing FromPyObject trait once the GIL Refs API was removed.

§Usage

Users are prevented from implementing this trait, instead they should implement the normal FromPyObject trait. This trait has a blanket implementation for T: FromPyObject.

The only case where this trait may have a use case to be implemented is when the lifetime of the extracted value is tied to the lifetime 'a of the input Bound instead of the GIL lifetime py, as is the case for the &'a str implementation.

Please contact the PyO3 maintainers if you believe you have a use case for implementing this trait before PyO3 is ready to change the main FromPyObject trait to take an additional lifetime.

Similarly, users should typically not call these trait methods and should instead use this via the extract method on Bound and Py.

Required Methods§

Source

fn from_py_object_bound(ob: Borrowed<'a, 'py, PyAny>) -> PyResult<Self>

Extracts Self from the bound smart pointer obj.

Users are advised against calling this method directly: instead, use this via [Bound<'_, PyAny>::extract] or Py::extract.

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> FromPyObjectBound<'a, '_> for &'a str

Source§

impl<'a> FromPyObjectBound<'a, '_> for &'a [u8]

Source§

impl<'a> FromPyObjectBound<'a, '_> for Cow<'a, str>

Source§

impl<'a> FromPyObjectBound<'a, '_> for Cow<'a, [u8]>

Implementors§

Source§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,