1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// Similar to the `TryFrom` trait proposed but not yet available in `std`.
pub trait TryFrom<T>: Sized {
    type Err: 'static;

    fn try_from(t: T) -> Result<Self, Self::Err>;
}

/// Similar to the `TryInto` trait proposed but not yet available in
/// `std`. Blanket implemented for all `TryFrom`.
pub trait TryInto<T>: Sized {
    type Err: 'static;

    fn try_into(self) -> Result<T, Self::Err>;
}

impl<T, F> TryInto<F> for T
where F: TryFrom<T>
{
    type Err = F::Err;

    fn try_into(self) -> Result<F, Self::Err> {
        F::try_from(self)
    }
}