10 releases (6 breaking)
Uses new Rust 2024
| new 0.44.1 | Mar 3, 2026 |
|---|---|
| 0.44.0 | Mar 1, 2026 |
| 0.43.2 | Jan 23, 2026 |
| 0.42.0 | Jan 6, 2026 |
| 0.35.0 | Dec 28, 2025 |
#2163 in Rust patterns
495 downloads per month
Used in 21 crates
(6 directly)
170KB
250 lines
facet-error
facet-error
A thiserror replacement powered by facet reflection. This crate is a plugin for #[derive(Facet)] that generates Display and Error trait implementations from doc comments.
Usage
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 MyErrorusing doc comments as format stringsimpl Error for MyErrorwith propersource()implementation- Field interpolation works automatically for struct variants (e.g.,
{expected},{found}) - Tuple variants support positional interpolation (e.g.,
{0})
Features
- Doc-driven Display: Doc comments become your error messages
- Field interpolation: Reference struct fields by name in messages
- Zero boilerplate: No manual Display or Error implementations
- Integration with facet: Works seamlessly with the facet reflection system
Future Work
#[facet(error::source)]- mark fields as error sources#[facet(error::from)]- generateFromimplementations- Support for error wrapping and transparent delegation
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~2MB
~39K SLoC