6 releases (3 breaking)
0.5.1 | Mar 1, 2022 |
---|---|
0.5.0 |
|
0.4.0 | Feb 13, 2022 |
0.3.2 | Sep 9, 2021 |
0.2.0 | Jun 29, 2021 |
#1335 in Rust patterns
Used in 9 crates
(8 directly)
14KB
159 lines
ebacktrace
Welcome to ebacktrace
🎉
This crate implements a simple error wrapper which captures a backtrace upon creation and can carry an optional textual description of the error.
Example
use ebacktrace::define_error;
use std::fmt::{ self, Display, Formatter };
/// The error kind
#[derive(Debug, Copy, Clone)]
enum ErrorKind {
MyErrorA,
Testolope
}
impl Display for ErrorKind {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{:#?}", self)
}
}
// Define our custom error type
define_error!(Error);
/// A function that will always fail
fn will_fail() -> Result<(), Error<ErrorKind>> {
Err(ErrorKind::Testolope)?
}
// Will panic with a nice error
if let Err(e) = will_fail() {
eprintln!("Error: {:?}", e);
panic!("Fatal error")
}
Features
This crate currently has one feature gate:
force_backtrace
(disabled by default): Ifforce_backtrace
is enable, the backtrace is always captured, regardless whetherRUST_BACKTRACE
is set or not.
Dependencies
~2.3–7.5MB
~67K SLoC