py_wrap_error

Macro py_wrap_error 

Source
macro_rules! py_wrap_error {
    ($module: ident, $rust: ty, $python: ident, $base: ty) => { ... };
}
Expand description

Creates a new exception type and implements converting from the given Rust error to the new exception.

The Rust error type must at least implement ToString. All types that implement Error implement this through Display.

use rigetti_pyo3::py_wrap_error;
use rigetti_pyo3::pyo3::exceptions::PyValueError;
use std::fmt;

#[derive(Debug)]
enum RustError {}

impl fmt::Display for RustError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        unimplemented!()
    }
}

impl std::error::Error for RustError {}

py_wrap_error!(my_python_module, RustError, PythonError, PyValueError);