radix_rust/
contextual_try_from_into.rs

1pub trait ContextualTryFrom<T>
2where
3    Self: Sized,
4{
5    type Context;
6    type Error;
7
8    fn contextual_try_from(value: T, context: &Self::Context) -> Result<Self, Self::Error>;
9}
10
11pub trait ContextualTryInto<T> {
12    type Context;
13    type Error;
14
15    fn contextual_try_into(self, context: &Self::Context) -> Result<T, Self::Error>;
16}
17
18impl<T, U> ContextualTryInto<U> for T
19where
20    U: ContextualTryFrom<T>,
21{
22    type Error = U::Error;
23    type Context = U::Context;
24
25    #[inline]
26    fn contextual_try_into(self, context: &U::Context) -> Result<U, U::Error> {
27        U::contextual_try_from(self, context)
28    }
29}