[][src]Trait to_trait::To

pub trait To {
    fn to<T>(self) -> T
    where
        Self: Into<T>
, { ... }
fn try_to<T>(self) -> Result<T, Self::Error>
    where
        Self: TryInto<T>
, { ... } }

Provides methods similar to .into() and .try_into(), except they take type arguments. See each method's documentation for details.

Provided methods

fn to<T>(self) -> T where
    Self: Into<T>, 

A version of std::convert::Into::into that lets you provide type arguments to the method call.

use to_trait::To;
assert_eq!(5i32, 5u8.to::<i32>());

fn try_to<T>(self) -> Result<T, Self::Error> where
    Self: TryInto<T>, 

a version of std::convert::TryInto::try_into that lets you provide type arguments to the method call.

use to_trait::To;
assert_eq!(255u32.try_to::<u8>(), Ok(255u8));
assert!(256u32.try_to::<u8>().is_err());
Loading content...

Implementors

impl<T> To for T[src]

Loading content...