16 releases (8 stable)

2.0.1 May 7, 2021
2.0.0 Aug 11, 2020
1.2.3 Jan 2, 2020
1.2.2 May 26, 2018
0.1.4 Oct 17, 2015

#1494 in Rust patterns

Download history 1280893/week @ 2025-07-01 1446487/week @ 2025-07-08 1708352/week @ 2025-07-15 1797815/week @ 2025-07-22 1739847/week @ 2025-07-29 1817031/week @ 2025-08-05 1774020/week @ 2025-08-12 1666738/week @ 2025-08-19 1692001/week @ 2025-08-26 1794860/week @ 2025-09-02 1733114/week @ 2025-09-09 1645731/week @ 2025-09-16 1694016/week @ 2025-09-23 1754470/week @ 2025-09-30 1742487/week @ 2025-10-07 1434150/week @ 2025-10-14

6,904,252 downloads per month
Used in fewer than 297 crates

MIT/Apache

49KB
962 lines

Quick Error

Status:production-ready
Documentation:https://docs.rs/quick-error/

A macro which makes error types pleasant to write.

Features:

  • Define enum type with arbitrary parameters
  • Concise notation of Display and Error traits
  • Full control of Display and Error trait implementation
  • Any number of From traits
  • Support for all enum-variants Unit, Tuple and Struct

Here is the comprehensive example:

quick_error! {
    #[derive(Debug)]
    pub enum IoWrapper {
        Io(err: io::Error) {
            from()
            display("I/O error: {}", err)
            source(err)
        }
        Other(descr: &'static str) {
            display("Error {}", descr)
        }
        IoAt { place: &'static str, err: io::Error } {
            source(err)
            display(me) -> ("io error at {}: {}", place, err)
            from(s: String) -> {
                place: "some string",
                err: io::Error::new(io::ErrorKind::Other, s)
            }
        }
        Discard {
            from(&'static str)
        }
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps