3 stable releases
| 2.1.0 | Mar 17, 2020 |
|---|---|
| 2.0.1 | Apr 13, 2019 |
| 2.0.0 | Apr 8, 2019 |
#2523 in Rust patterns
21 downloads per month
49KB
964 lines
============= Quick Error 2
This is https://github.com/tailhook/quick-error but upgraded to Rust 2018 and
support for Error::source(). It has been published as quick-error2. You
can upgrade by updating your Cargo.toml to
.. code-block:: toml
[dependencies]
quick-error = { package = "quick-error2", version = "2" }
Why?
Because there hasn't been a release yet of quick-error version 2.* 🤷♂️.
=========== 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
DisplayandErrortraits - Full control of
DisplayandErrortrait implementation - Any number of
Fromtraits - Support for all enum-variants
Unit,TupleandStruct
Here is the comprehensive example:
.. code-block:: rust
quick_error! {
#[derive(Debug)]
pub enum IoWrapper {
Io(err: io::Error) {
from()
display("I/O error: {}", err)
cause(err)
}
Other(descr: &'static str) {
display("Error {}", descr)
}
IoAt { place: &'static str, err: io::Error } {
cause(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
- 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.
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.