facet-error

facet-error is a thiserror-style plugin for #[derive(Facet)] that generates Display and Error implementations from doc comments. You write the error message once as a doc comment; facet-error turns it into a Display impl with field interpolation, so there's nothing else to maintain.

rust
use facet::Facet;

#[derive(Facet, Debug)]
#[facet(derive(Error))]
#[repr(u8)]
pub enum MyError {
    /// something went wrong
    Unknown,

    /// invalid value: {0}
    InvalidValue(String),

    /// invalid header (expected {expected}, found {found})
    InvalidHeader { expected: String, found: String },
}

This generates impl Display for MyError using the doc comments as format strings, plus impl Error for MyError with a proper source() implementation. Struct variants interpolate fields by name; tuple variants use positional {0}, {1}, etc.

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.