orion_error/traits/
contextual.rs

1use crate::OperationContext;
2
3pub trait ErrorWith {
4    fn want<S: Into<String>>(self, desc: S) -> Self;
5    fn position<S: Into<String>>(self, desc: S) -> Self;
6    fn with<C: Into<OperationContext>>(self, ctx: C) -> Self;
7}
8
9impl<T, E: ErrorWith> ErrorWith for Result<T, E> {
10    fn want<S: Into<String>>(self, desc: S) -> Self {
11        self.map_err(|e| e.want(desc))
12    }
13    fn position<S: Into<String>>(self, desc: S) -> Self {
14        self.map_err(|e| e.position(desc))
15    }
16    fn with<C: Into<OperationContext>>(self, ctx: C) -> Self {
17        self.map_err(|e| e.with(ctx))
18    }
19}