Expand description
§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 two feature gates:
derive_display
(enabled by default): Use theDisplay
-trait forEtrace<MyType>
using theDebug
representation ofMyType
(instead of theDisplay
representation). This way you can pretty-print the underlying error types without the necessity to manually implement theDisplay
-trait for them.force_backtrace
(disabled by default): Ifforce_backtrace
is enable, the backtrace is always captured, regardless whetherRUST_BACKTRACE
is set or not.
Macros§
- define_
error - Defines a custom error generic
$name<E>
whereE
is an arbitrary payload type