pub trait ErrorContext<T, E> {
// Required methods
fn context(self, context: impl Display) -> Result<T>;
fn with_context<F>(self, f: F) -> Result<T>
where F: FnOnce() -> String;
}Expand description
Trait for adding context to errors.
This trait allows chaining contextual information to errors, making it easier to track the source and cause of errors.
§Example
use rh_foundation::ErrorContext;
fn read_config() -> rh_foundation::Result<String> {
std::fs::read_to_string("config.json")
.context("Failed to read configuration file")?;
Ok("config".to_string())
}Required Methods§
Sourcefn with_context<F>(self, f: F) -> Result<T>
fn with_context<F>(self, f: F) -> Result<T>
Add context with a function (lazy evaluation)
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.