| 1 |
=========== |
| 2 |
Quick Error |
| 3 |
=========== |
| 4 |
|
| 5 |
:Status: production-ready |
| 6 |
:Documentation: https://docs.rs/quick-error/ |
| 7 |
|
| 8 |
A macro which makes error types pleasant to write. |
| 9 |
|
| 10 |
Features: |
| 11 |
|
| 12 |
* Define enum type with arbitrary parameters |
| 13 |
* Concise notation of ``Display`` and ``Error`` traits |
| 14 |
* Full control of ``Display`` and ``Error`` trait implementation |
| 15 |
* Any number of ``From`` traits |
| 16 |
* Support for all enum-variants ``Unit``, ``Tuple`` and ``Struct`` |
| 17 |
|
| 18 |
Here is the comprehensive example: |
| 19 |
|
| 20 |
.. code-block:: rust |
| 21 |
|
| 22 |
quick_error! { |
| 23 |
#[derive(Debug)] |
| 24 |
pub enum IoWrapper { |
| 25 |
Io(err: io::Error) { |
| 26 |
from() |
| 27 |
display("I/O error: {}", err) |
| 28 |
source(err) |
| 29 |
} |
| 30 |
Other(descr: &'static str) { |
| 31 |
display("Error {}", descr) |
| 32 |
} |
| 33 |
IoAt { place: &'static str, err: io::Error } { |
| 34 |
source(err) |
| 35 |
display(me) -> ("io error at {}: {}", place, err) |
| 36 |
from(s: String) -> { |
| 37 |
place: "some string", |
| 38 |
err: io::Error::new(io::ErrorKind::Other, s) |
| 39 |
} |
| 40 |
} |
| 41 |
Discard { |
| 42 |
from(&'static str) |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
======= |
| 48 |
License |
| 49 |
======= |
| 50 |
|
| 51 |
Licensed under either of |
| 52 |
|
| 53 |
* Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) |
| 54 |
* MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) |
| 55 |
|
| 56 |
at your option. |
| 57 |
|
| 58 |
------------ |
| 59 |
Contribution |
| 60 |
------------ |
| 61 |
|
| 62 |
Unless you explicitly state otherwise, any contribution intentionally |
| 63 |
submitted for inclusion in the work by you, as defined in the Apache-2.0 |
| 64 |
license, shall be dual licensed as above, without any additional terms or |
| 65 |
conditions. |
| 66 |
|