1// Allow tide Results to accept context like other Results do when
2// using anyhow.
3pub trait TideResultExt {
4 fn context<C>(self, cx: C) -> Self
5 where
6 C: std::fmt::Display + Send + Sync + 'static;
7
8 fn with_context<C, F>(self, f: F) -> Self
9 where
10 C: std::fmt::Display + Send + Sync + 'static,
11 F: FnOnce() -> C;
12}
13
14impl<T> TideResultExt for tide::Result<T> {
15 fn context<C>(self, cx: C) -> Self
16 where
17 C: std::fmt::Display + Send + Sync + 'static,
18 {
19 self.map_err(|e| tide::Error::new(e.status(), e.into_inner().context(cx)))
20 }
21
22 fn with_context<C, F>(self, f: F) -> Self
23 where
24 C: std::fmt::Display + Send + Sync + 'static,
25 F: FnOnce() -> C,
26 {
27 self.map_err(|e| tide::Error::new(e.status(), e.into_inner().context(f())))
28 }
29}