pub trait Error2: Error {
// Required methods
fn backtrace(&self) -> &Backtrace;
fn backtrace_mut(&mut self) -> &mut Backtrace;
}Expand description
Core trait extending std::error::Error with backtrace support.
Error2 provides methods to access and modify the error’s backtrace,
enabling detailed error propagation tracking across your application.
§Implementation
Typically implemented via #[derive(Error2)] macro:
use error2::prelude::*;
#[derive(Debug, Error2)]
#[error2(display("configuration error"))]
struct ConfigError {
backtrace: Backtrace,
}The macro automatically generates the trait implementation and manages the backtrace field.
§Accessing Backtrace
Use the .backtrace() method to access error chain and locations:
if let Err(e) = do_something() {
println!("{}", e.backtrace().error_message());
}See Backtrace for details on accessing error information.
Required Methods§
Sourcefn backtrace(&self) -> &Backtrace
fn backtrace(&self) -> &Backtrace
Returns a reference to the error’s backtrace.
The backtrace contains the complete error chain and location information.
Sourcefn backtrace_mut(&mut self) -> &mut Backtrace
fn backtrace_mut(&mut self) -> &mut Backtrace
Returns a mutable reference to the error’s backtrace.
Used internally by the library to record error propagation locations.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".