pub trait AnyErrorToPyErr {
// Required methods
fn try_from_err<T: MapErrorToPyErr>(
py: Python<'_>,
err: Box<dyn Error + 'static>,
) -> Result<PyErr, Box<dyn Error + 'static>>;
fn try_from_err_ref<T: MapErrorToPyErr>(
py: Python<'_>,
err: &(dyn Error + 'static),
) -> Option<PyErr>;
}
Expand description
Utility trait to try to translate from std::error::Error
to PyErr
.
ErrorNoPyErr
may be used to always fail at translating.
IoErrorToPyErr
may be used to translate std::io::Error
to PyErr
.
Required Methods§
Sourcefn try_from_err<T: MapErrorToPyErr>(
py: Python<'_>,
err: Box<dyn Error + 'static>,
) -> Result<PyErr, Box<dyn Error + 'static>>
fn try_from_err<T: MapErrorToPyErr>( py: Python<'_>, err: Box<dyn Error + 'static>, ) -> Result<PyErr, Box<dyn Error + 'static>>
Try to translate from a boxed err
to a PyErr
, or return the err
.
When a strongly typed translation from some specific error type E
to a
PyErr
is attempted, MapErrorToPyErr::try_map
should be used to allow
the mapper to test for E
in addition to wrapped errors such as
MyError<E>
.
§Errors
Returns the original err
if translating to a PyErr
failed.
Sourcefn try_from_err_ref<T: MapErrorToPyErr>(
py: Python<'_>,
err: &(dyn Error + 'static),
) -> Option<PyErr>
fn try_from_err_ref<T: MapErrorToPyErr>( py: Python<'_>, err: &(dyn Error + 'static), ) -> Option<PyErr>
Try to translate from an err
reference to a PyErr
, or return
None
.
When a strongly typed translation from some specific error type E
to a
PyErr
is attempted, MapErrorToPyErr::try_map_ref
should be used to
allow the mapper to test for E
in addition to wrapped errors such as
MyError<E>
.
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.