orion_error/traits/
contextual.rs1use crate::core::OperationContext;
2
3pub trait ErrorWith {
4 #[deprecated(
5 since = "0.7.0",
6 note = "use doing(...) for action contexts; use at(...) for locator/resource contexts"
7 )]
8 fn want<S: Into<String>>(self, desc: S) -> Self;
9 fn position<S: Into<String>>(self, desc: S) -> Self;
10 fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self;
11 #[deprecated(
12 since = "0.7.0",
13 note = "use with_context(...) for full context frames; use doing(...) / at(...) for semantic context helpers"
14 )]
15 fn attach_context<C: Into<OperationContext>>(self, ctx: C) -> Self
16 where
17 Self: Sized,
18 {
19 self.with_context(ctx)
20 }
21 #[deprecated(
22 since = "0.7.0",
23 note = "use with_context(...) for full context frames; use at(...) / doing(...) for semantic context helpers"
24 )]
25 fn with<C: Into<OperationContext>>(self, ctx: C) -> Self
26 where
27 Self: Sized,
28 {
29 self.with_context(ctx)
30 }
31 fn doing<S: Into<String>>(self, desc: S) -> Self
32 where
33 Self: Sized,
34 {
35 self.with_context(OperationContext::doing(desc))
36 }
37 fn at<C: Into<OperationContext>>(self, ctx: C) -> Self
38 where
39 Self: Sized,
40 {
41 self.with_context(ctx.into().into_at_context())
42 }
43}
44
45impl<T, E: ErrorWith> ErrorWith for Result<T, E> {
46 #[allow(deprecated)]
47 fn want<S: Into<String>>(self, desc: S) -> Self {
48 self.map_err(|e| e.want(desc))
49 }
50 fn position<S: Into<String>>(self, desc: S) -> Self {
51 self.map_err(|e| e.position(desc))
52 }
53 fn with_context<C: Into<OperationContext>>(self, ctx: C) -> Self {
54 self.map_err(|e| e.with_context(ctx))
55 }
56}