pub trait SourceContext<T, E> {
// Required methods
fn with_source_context(self, context: impl FnOnce() -> String) -> Result<T>;
fn source_context<C>(self, context: C) -> Result<T>
where C: Display + Send + Sync + 'static;
}Required Methods§
Sourcefn with_source_context(self, context: impl FnOnce() -> String) -> Result<T>
fn with_source_context(self, context: impl FnOnce() -> String) -> Result<T>
Similar to with_context in anyhow::Context, but adds the source location of the
caller. This is especially useful when generating a message to attach to an error object as
the context.
Example:
let mount_point = system_task
.lookup_path_from_root(locked, mount_point)
.with_source_context(|| {
format!("lookup path from root: {}", String::from_utf8_lossy(mount_point))
})?;Results in a context message like:
Caused by:
1: lookup path from root: ..., some_file.rs:12:34Sourcefn source_context<C>(self, context: C) -> Result<T>
fn source_context<C>(self, context: C) -> Result<T>
Similar to context in anyhow::Context, but adds the source location of the caller.
This is especially useful when generating a message to attach to an error object as the
context.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.