radix_rust/
contextual_try_from_into.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
pub trait ContextualTryFrom<T>
where
    Self: Sized,
{
    type Context;
    type Error;

    fn contextual_try_from(value: T, context: &Self::Context) -> Result<Self, Self::Error>;
}

pub trait ContextualTryInto<T> {
    type Context;
    type Error;

    fn contextual_try_into(self, context: &Self::Context) -> Result<T, Self::Error>;
}

impl<T, U> ContextualTryInto<U> for T
where
    U: ContextualTryFrom<T>,
{
    type Error = U::Error;
    type Context = U::Context;

    #[inline]
    fn contextual_try_into(self, context: &U::Context) -> Result<U, U::Error> {
        U::contextual_try_from(self, context)
    }
}