pyo3::conversion

Trait IntoPyObjectExt

Source
pub trait IntoPyObjectExt<'py>: IntoPyObject<'py> + Sealed {
    // Provided methods
    fn into_bound_py_any(self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> { ... }
    fn into_py_any(self, py: Python<'py>) -> PyResult<Py<PyAny>> { ... }
    fn into_pyobject_or_pyerr(self, py: Python<'py>) -> PyResult<Self::Output> { ... }
}
Expand description

Convenience methods for common usages of IntoPyObject. Every type that implements IntoPyObject also implements this trait.

These methods:

  • Drop type information from the output, returning a PyAny object.
  • Always convert the Error type to PyErr, which may incur a performance penalty but it more convenient in contexts where the ? operator would produce a PyErr anyway.

Provided Methods§

Source

fn into_bound_py_any(self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>>

Converts self into an owned Python object, dropping type information.

Source

fn into_py_any(self, py: Python<'py>) -> PyResult<Py<PyAny>>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.

Source

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> PyResult<Self::Output>

Converts self into a Python object.

This is equivalent to calling into_pyobject followed with .map_err(Into::into) to convert the error type to PyErr. This is helpful for generic code which wants to make use of the ? operator.

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.

Implementors§

Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,