pyo3_error

Trait MapErrorToPyErr

Source
pub trait MapErrorToPyErr {
    // Required methods
    fn try_map<T: Error + 'static>(
        py: Python<'_>,
        err: Box<dyn Error + 'static>,
        map: impl FnOnce(Box<T>) -> PyErr,
    ) -> Result<PyErr, Box<dyn Error + 'static>>;
    fn try_map_send_sync<T: Error + 'static>(
        py: Python<'_>,
        err: Box<dyn Error + Send + Sync + 'static>,
        map: impl FnOnce(Box<T>) -> PyErr,
    ) -> Result<PyErr, Box<dyn Error + Send + Sync + 'static>>;
    fn try_map_ref<T: Error + 'static>(
        py: Python<'_>,
        err: &(dyn Error + 'static),
        map: impl FnOnce(&T) -> PyErr,
    ) -> Option<PyErr>;
}
Expand description

Utility trait to try to translate via specific error types E implementing std::error::Error and wrapped errors such as MyError<E> to PyErrs.

DowncastToPyErr may be used to only try to translate via E using downcasting.

Required Methods§

Source

fn try_map<T: Error + 'static>( py: Python<'_>, err: Box<dyn Error + 'static>, map: impl FnOnce(Box<T>) -> PyErr, ) -> Result<PyErr, Box<dyn Error + 'static>>

Try to map from a boxed err via the specific error type T or wrapped errors such as MyError<E> to a PyErr, or return the err.

The map function should be used to access the provided mapping from T to PyErr.

§Errors

Returns the original err if mapping to a PyErr failed.

Source

fn try_map_send_sync<T: Error + 'static>( py: Python<'_>, err: Box<dyn Error + Send + Sync + 'static>, map: impl FnOnce(Box<T>) -> PyErr, ) -> Result<PyErr, Box<dyn Error + Send + Sync + 'static>>

Try to map from a boxed err via the specific error type T or wrapped errors such as MyError<E> to a PyErr, or return the err.

The map function should be used to access the provided mapping from T to PyErr.

§Errors

Returns the original err if mapping to a PyErr failed.

Source

fn try_map_ref<T: Error + 'static>( py: Python<'_>, err: &(dyn Error + 'static), map: impl FnOnce(&T) -> PyErr, ) -> Option<PyErr>

Try to map from an err reference via the specific error type T or wrapped errors such as MyError<E> to a PyErr, or return None.

The map function should be used to access the provided mapping from &T to PyErr.

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§