stdweb/webcore/try_from.rs
1/// Attempt to construct Self via a conversion.
2///
3/// This definition is only temporary until Rust's `TryFrom` is stabilized.
4pub trait TryFrom< T >: Sized {
5 /// The type returned in the event of a conversion error.
6 type Error;
7
8 /// Performs the conversion.
9 fn try_from( T ) -> Result< Self, Self::Error >;
10}
11
12/// An attempted conversion that consumes self, which may or may not be expensive.
13///
14/// This definition is only temporary until Rust's `TryInto` is stabilized.
15pub trait TryInto< T >: Sized {
16 /// The type returned in the event of a conversion error.
17 type Error;
18
19 /// Performs the conversion.
20 fn try_into( self ) -> Result< T, Self::Error >;
21}
22
23impl< T, U > TryInto< U > for T where U: TryFrom< T > {
24 type Error = U::Error;
25 #[inline]
26 fn try_into( self ) -> Result< U, U::Error > {
27 U::try_from( self )
28 }
29}