Re-export of color-eyre that introduces Extensions (type-map) to eyre::Report.
This is a simple wrapper around color_eyre
with everything equal,
and just introduces traits ExtensionExt
, Extension
for adding and accessing custom data.
To learn more about color-eyre
, see their documentation.
extension_eyre
helps you add extensions of any type to your error like this:
Add the following to your toml file:
toml
[dependencies]
extension-eyre = "0.1"
And install the panic and error report handlers:
```rust use extension_eyre::eyre::Result;
fn main() -> Result<()> { extension_eyre::install()?;
// ...
# Ok(())
} ```
For all the features introduced by color-eyre
, please see their documentation.
ExtensionExt
] traitThe crate exposes ExtensionExt
trait for adding and
Extension
trait for accessing extra data to error reports.
The extensions implementation is a copy of http crate's
Extensions implementation.
ExtensionExt
allows adding data of any type to error reports. At the application level,
you can access this data with trait Extension
with method report.extension_ref::<T>()
.
```rust use extension_eyre::{eyre::eyre, ExtensionExt, Extension, eyre::Report}; use std::process::Command; use tracing::instrument;
pub struct Retry;
fn app(path: &str) -> Result
Ok(Default::default())
}
fn read_file(path: &str) -> Result
trait Output {
fn output2(&mut self) -> Result
impl Output for Command {
#[instrument]
fn output2(&mut self) -> Result
let stdout = String::from_utf8_lossy(&output.stdout);
if !output.status.success() {
Err(eyre!("cmd exited with non-zero status code")).extension(Retry)
} else {
Ok(stdout.into())
}
}
} ```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.