conv

Trait TryFrom

Source
pub trait TryFrom<Src>: Sized {
    type Err: Error;

    // Required method
    fn try_from(src: Src) -> Result<Self, Self::Err>;
}
Expand description

This trait is used to perform a conversion between different semantic types which might fail.

Where possible, prefer implementing this trait over TryInto, but prefer using TryInto for generic constraints.

§Details

Typically, this should be used in cases where you are converting between values whose ranges and/or representations only partially overlap. That the conversion may fail should be a reasonably expected outcome. A standard example of this is converting from integers to enums of unitary variants.

Required Associated Types§

Source

type Err: Error

The error type produced by a failed conversion.

Required Methods§

Source

fn try_from(src: Src) -> Result<Self, Self::Err>

Convert the given value into the subject type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TryFrom<char> for i8

Source§

impl TryFrom<char> for i16

Source§

impl TryFrom<char> for i32

Source§

impl TryFrom<char> for i64

Source§

impl TryFrom<char> for isize

Source§

impl TryFrom<char> for u8

Source§

impl TryFrom<char> for u16

Source§

impl TryFrom<char> for u32

Source§

impl TryFrom<char> for u64

Source§

impl TryFrom<char> for usize

Source§

impl TryFrom<i8> for char

Source§

impl TryFrom<i16> for char

Source§

impl TryFrom<i32> for char

Source§

impl TryFrom<i64> for char

Source§

impl TryFrom<isize> for char

Source§

impl TryFrom<u8> for char

Source§

impl TryFrom<u16> for char

Source§

impl TryFrom<u32> for char

Source§

impl TryFrom<u64> for char

Source§

impl TryFrom<usize> for char

Implementors§

Source§

impl<Src> TryFrom<Src> for Src