Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 652 Bytes

README.md

File metadata and controls

33 lines (27 loc) · 652 Bytes

pyexc

An easy way to define Python exceptions.

use pyexc::PythonException;

#[derive(PythonException)]
pub enum MyBaseException {
    #[base(module = "errors")]
    #[format("Hello")]
    Base,
    #[format("World")]
    Bar,
    #[format("!")]
    Baz,
}

// Inheritance is experimental!

#[derive(PythonException)]
pub enum MySubException {
    #[base(module = "other_errors", inherits = "errors.MyBaseException")]
    #[format("Error!")]
    BaseBase,
    #[format("SEGFAULT")]
    FooBar,
    #[format("Fatal!")]
    FooBaz,
}

Allows usage in Result, as well as providing a generally Rust-like interface for Python exceptions.