use crate::error::DbError;
pub(crate) type DbResult<R> = Result<R, DbError>;
pub(crate) trait DbResultHelper<T> {
fn context(self, context: &str) -> DbResult<T>;
}
impl<T, E> DbResultHelper<T> for Result<T, E>
where
E: std::error::Error,
{
fn context(self, context: &str) -> DbResult<T> {
self.map_err(|e| DbError::ServerError(format!("{context}: {e}")))
}
}
impl<T> DbResultHelper<T> for Option<T> {
fn context(self, context: &str) -> DbResult<T> {
self.ok_or_else(|| DbError::ServerError(context.to_owned()))
}
}