use anyhow::{Context, Result};
#[macro_export]
macro_rules! context_wrap {
($result:expr, $operation:expr) => {
$result.context(format!("Failed to {}", $operation))
};
}
pub trait ResultExt<T> {
fn context_op(self, operation: &str) -> Result<T>;
fn context_path(self, operation: &str, path: &std::path::Path) -> Result<T>;
}
impl<T, E> ResultExt<T> for std::result::Result<T, E>
where
E: std::error::Error + Send + Sync + 'static,
{
fn context_op(self, operation: &str) -> Result<T> {
self.context(format!("Failed to {}", operation))
}
fn context_path(self, operation: &str, path: &std::path::Path) -> Result<T> {
self.context(format!("Failed to {} at '{}'", operation, path.display()))
}
}