pub trait ErrorAtExt: Sized {
// Required method
fn start_at(self) -> At<Self>;
}Expand description
Extension trait that allows calling .start_at() on error types.
This trait is implemented for all types that implement core::error::Error.
For types without Error, use the at() function or at!() macro instead.
use whereat::{ErrorAtExt, ResultAtExt};
use core::fmt;
#[derive(Debug)]
enum MyError { NotFound }
impl fmt::Display for MyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { MyError::NotFound => write!(f, "not found") }
}
}
impl core::error::Error for MyError {}
fn inner() -> Result<(), whereat::At<MyError>> {
Err(MyError::NotFound.start_at())
}
fn outer() -> Result<(), whereat::At<MyError>> {
inner().at()?; // .at() adds another location
Ok(())
}Required Methods§
Sourcefn start_at(self) -> At<Self>
fn start_at(self) -> At<Self>
Wrap this value in At<E> and add the caller’s location.
If allocation fails, the error is still wrapped but trace may be empty.
For crate-aware tracing with repository links, use at!(err) instead.
Requires define_at_crate_info!() in your crate root.
After calling .start_at(), you can chain context methods:
.at_str("msg")- static string context (zero-cost).at_string(|| format!(...))- lazy string context.at_data(|| value)- lazy typed context (Display).at_debug(|| value)- lazy typed context (Debug)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".