geez 0.1.0

geez — Global Error Embedding Zero-cost. Declarative error enums, thiserror-like attrs, zero deps
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 41.88 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 379.18 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • theHamdiz/geez
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • theHamdiz

geez

Global Error Embedding Zero-cost.

Typed error enums with attributes that look like thiserror, implemented as a plain macro_rules! macro. No proc-macros, no dependencies.

Add it

[dependencies]

geez = "0.1"

Use it

use geez::geez;

geez! {
    pub enum AppError {
        #[from]
        Io(std::io::Error),

        #[transparent]
        Other(OtherError),

        #[source]
        Wrapped(std::io::Error),

        #[error("bad status {0}: {1}")]
        Status(u16, String),

        #[error("parse failed: {0}")]
        Parse(String),

        Timeout => "request timed out",

        NotFound,
    }
}

fn load() -> Result<()> {
    std::fs::read_to_string("config.toml")?;
    Ok(())
}

That also defines type Result<T> = std::result::Result<T, AppError> with the same visibility as the enum.

Attributes

Write this What you get
#[from] From<T> + Error::source (one field)
#[transparent] From<T>, Display and source forward to the inner error (one field)
#[source] Error::source only — no From (one field)
#[error("…")] Custom Display. Use {0}, {1}, … for fields
=> "…" Same as #[error("…")], handy for unit variants
unit, no message Display is the variant name (NotFound)
one field, no message Display is "{}" of the field

#[from], #[transparent], and #[source] are mutually exclusive. Multi-field variants need an #[error("…")] (or =>).

Tuple variants support up to 8 fields.

vs thiserror / anyhow

thiserror is a proc-macro with a bigger feature set (struct variants, field-level #[source], more format sugar). Reach for it when you need that, or when you already depend on it.

anyhow is one opaque error type plus context helpers. Great for binaries and apps. Not what you want for a library’s public error enum.

geez sits in the thiserror lane: typed enums for libraries, familiar attributes, zero deps, declarative macro only. Use it when you want a small error enum without pulling in syn.

License

MIT OR Apache-2.0