orion_error/traits/
contextual.rs1use 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 fn doing<S: Into<String>>(self, desc: S) -> Self
8 where
9 Self: Sized,
10 {
11 self.want(desc)
12 }
13 fn at<C: Into<OperationContext>>(self, ctx: C) -> Self
14 where
15 Self: Sized,
16 {
17 self.with(ctx)
18 }
19}
20
21impl<T, E: ErrorWith> ErrorWith for Result<T, E> {
22 fn want<S: Into<String>>(self, desc: S) -> Self {
23 self.map_err(|e| e.want(desc))
24 }
25 fn position<S: Into<String>>(self, desc: S) -> Self {
26 self.map_err(|e| e.position(desc))
27 }
28 fn with<C: Into<OperationContext>>(self, ctx: C) -> Self {
29 self.map_err(|e| e.with(ctx))
30 }
31}