Trait core::convert::From 1.0.0[−][src]
Simple and safe type conversions in to Self
. It is the reciprocal of
Into
.
This trait is useful when performing error handling as described by
the book and is closely related to the ?
operator.
When constructing a function that is capable of failing the return type
will generally be of the form Result<T, E>
.
The From
trait allows for simplification of error handling by providing a
means of returning a single error type that encapsulates numerous possible
erroneous situations.
This trait is not limited to error handling, rather the general case for this trait would be in any type conversions to have an explicit definition of how they are performed.
Note: this trait must not fail. If the conversion can fail, use
TryFrom
or a dedicated method which returns an Option<T>
or a
Result<T, E>
.
Generic Implementations
Examples
String
implements From<&str>
:
let string = "hello".to_string(); let other_string = String::from("hello"); assert_eq!(string, other_string);Run
An example usage for error handling:
use std::io::{self, Read}; use std::num; enum CliError { IoError(io::Error), ParseError(num::ParseIntError), } impl From<io::Error> for CliError { fn from(error: io::Error) -> Self { CliError::IoError(error) } } impl From<num::ParseIntError> for CliError { fn from(error: num::ParseIntError) -> Self { CliError::ParseError(error) } } fn open_and_parse_file(file_name: &str) -> Result<i32, CliError> { let mut file = std::fs::File::open("test")?; let mut contents = String::new(); file.read_to_string(&mut contents)?; let num: i32 = contents.trim().parse()?; Ok(num) }Run
Required Methods
fn from(_: T) -> Self
Performs the conversion.
Implementors
impl From<!> for TryFromIntError
impl From<bool> for u8
impl From<bool> for u16
impl From<bool> for u32
impl From<bool> for u64
impl From<bool> for u128
impl From<bool> for usize
impl From<bool> for i8
impl From<bool> for i16
impl From<bool> for i32
impl From<bool> for i64
impl From<bool> for i128
impl From<bool> for isize
impl From<u8> for u16
impl From<u8> for u32
impl From<u8> for u64
impl From<u8> for u128
impl From<u8> for usize
impl From<u16> for u32
impl From<u16> for u64
impl From<u16> for u128
impl From<u32> for u64
impl From<u32> for u128
impl From<u64> for u128
impl From<i8> for i16
impl From<i8> for i32
impl From<i8> for i64
impl From<i8> for i128
impl From<i8> for isize
impl From<i16> for i32
impl From<i16> for i64
impl From<i16> for i128
impl From<i32> for i64
impl From<i32> for i128
impl From<i64> for i128
impl From<u8> for i16
impl From<u8> for i32
impl From<u8> for i64
impl From<u8> for i128
impl From<u16> for i32
impl From<u16> for i64
impl From<u16> for i128
impl From<u32> for i64
impl From<u32> for i128
impl From<u64> for i128
impl From<u16> for usize
impl From<u8> for isize
impl From<i16> for isize
impl From<i8> for f32
impl From<i8> for f64
impl From<i16> for f32
impl From<i16> for f64
impl From<i32> for f64
impl From<u8> for f32
impl From<u8> for f64
impl From<u16> for f32
impl From<u16> for f64
impl From<u32> for f64
impl From<f32> for f64
impl<'a, T: ?Sized> From<&'a mut T> for NonNull<T>
impl<'a, T: ?Sized> From<&'a T> for NonNull<T>
impl<T> From<T> for T
impl From<bool> for AtomicBool
impl<T> From<*mut T> for AtomicPtr<T>
impl From<i8> for AtomicI8
impl From<u8> for AtomicU8
impl From<i16> for AtomicI16
impl From<u16> for AtomicU16
impl From<i32> for AtomicI32
impl From<u32> for AtomicU32
impl From<i64> for AtomicI64
impl From<u64> for AtomicU64
impl From<isize> for AtomicIsize
impl From<usize> for AtomicUsize
impl<T> From<T> for Cell<T>
impl<T> From<T> for RefCell<T>
impl<T> From<T> for UnsafeCell<T>
impl From<char> for u32
impl From<u8> for char
impl<T> From<T> for Option<T>
impl<T> From<T> for Poll<T>
impl From<LocalWaker> for Waker
impl From<AllocErr> for CollectionAllocErr
impl From<LayoutErr> for CollectionAllocErr
impl From<f32x2> for f64x2
impl From<u64x2> for f64x2
impl From<i64x2> for f64x2
impl From<m64x2> for f64x2
impl From<u32x2> for f64x2
impl From<i32x2> for f64x2
impl From<m32x2> for f64x2
impl From<u16x2> for f64x2
impl From<i16x2> for f64x2
impl From<m16x2> for f64x2
impl From<u8x2> for f64x2
impl From<i8x2> for f64x2
impl From<m8x2> for f64x2
impl From<f64x2> for u64x2
impl From<i64x2> for u64x2
impl From<m64x2> for u64x2
impl From<f32x2> for u64x2
impl From<i32x2> for u64x2
impl From<u32x2> for u64x2
impl From<m32x2> for u64x2
impl From<i16x2> for u64x2
impl From<u16x2> for u64x2
impl From<m16x2> for u64x2
impl From<i8x2> for u64x2
impl From<u8x2> for u64x2
impl From<m8x2> for u64x2
impl From<f64x2> for i64x2
impl From<u64x2> for i64x2
impl From<m64x2> for i64x2
impl From<i32x2> for i64x2
impl From<u32x2> for i64x2
impl From<f32x2> for i64x2
impl From<m32x2> for i64x2
impl From<i16x2> for i64x2
impl From<u16x2> for i64x2
impl From<m16x2> for i64x2
impl From<i8x2> for i64x2
impl From<u8x2> for i64x2
impl From<m8x2> for i64x2
impl From<f64x4> for u32x4
impl From<u64x4> for u32x4
impl From<i64x4> for u32x4
impl From<m64x4> for u32x4
impl From<f32x4> for u32x4
impl From<i32x4> for u32x4
impl From<m32x4> for u32x4
impl From<u16x4> for u32x4
impl From<i16x4> for u32x4
impl From<m16x4> for u32x4
impl From<u8x4> for u32x4
impl From<i8x4> for u32x4
impl From<m8x4> for u32x4
impl From<f64x4> for i32x4
impl From<u64x4> for i32x4
impl From<i64x4> for i32x4
impl From<m64x4> for i32x4
impl From<f32x4> for i32x4
impl From<u32x4> for i32x4
impl From<m32x4> for i32x4
impl From<u16x4> for i32x4
impl From<i16x4> for i32x4
impl From<m16x4> for i32x4
impl From<u8x4> for i32x4
impl From<i8x4> for i32x4
impl From<m8x4> for i32x4
impl From<f64x4> for f32x4
impl From<u64x4> for f32x4
impl From<i64x4> for f32x4
impl From<m64x4> for f32x4
impl From<u32x4> for f32x4
impl From<i32x4> for f32x4
impl From<m32x4> for f32x4
impl From<u16x4> for f32x4
impl From<i16x4> for f32x4
impl From<m16x4> for f32x4
impl From<u8x4> for f32x4
impl From<i8x4> for f32x4
impl From<m8x4> for f32x4
impl From<f64x8> for i16x8
impl From<u64x8> for i16x8
impl From<i64x8> for i16x8
impl From<m1x8> for i16x8
impl From<f32x8> for i16x8
impl From<u32x8> for i16x8
impl From<i32x8> for i16x8
impl From<m32x8> for i16x8
impl From<u16x8> for i16x8
impl From<m16x8> for i16x8
impl From<u8x8> for i16x8
impl From<i8x8> for i16x8
impl From<m8x8> for i16x8
impl From<f64x8> for u16x8
impl From<u64x8> for u16x8
impl From<i64x8> for u16x8
impl From<m1x8> for u16x8
impl From<f32x8> for u16x8
impl From<u32x8> for u16x8
impl From<i32x8> for u16x8
impl From<m32x8> for u16x8
impl From<i16x8> for u16x8
impl From<m16x8> for u16x8
impl From<u8x8> for u16x8
impl From<i8x8> for u16x8
impl From<m8x8> for u16x8
impl From<i32x16> for u8x16
impl From<u32x16> for u8x16
impl From<f32x16> for u8x16
impl From<m1x16> for u8x16
impl From<i16x16> for u8x16
impl From<u16x16> for u8x16
impl From<m16x16> for u8x16
impl From<i8x16> for u8x16
impl From<m8x16> for u8x16
impl From<i32x16> for i8x16
impl From<u32x16> for i8x16
impl From<f32x16> for i8x16
impl From<m1x16> for i8x16
impl From<i16x16> for i8x16
impl From<u16x16> for i8x16
impl From<m16x16> for i8x16
impl From<u8x16> for i8x16
impl From<m8x16> for i8x16
impl From<m1x16> for m8x16
impl From<m16x16> for m8x16
impl From<m1x8> for m16x8
impl From<m32x8> for m16x8
impl From<m8x8> for m16x8
impl From<m64x4> for m32x4
impl From<m16x4> for m32x4
impl From<m8x4> for m32x4
impl From<m32x2> for m64x2
impl From<m16x2> for m64x2
impl From<m8x2> for m64x2
impl From<f64x2> for i8x2
impl From<u64x2> for i8x2
impl From<m64x2> for i8x2
impl From<i64x2> for i8x2
impl From<f32x2> for i8x2
impl From<u32x2> for i8x2
impl From<i32x2> for i8x2
impl From<m32x2> for i8x2
impl From<u16x2> for i8x2
impl From<m16x2> for i8x2
impl From<u8x2> for i8x2
impl From<m8x2> for i8x2
impl From<f64x2> for u8x2
impl From<u64x2> for u8x2
impl From<i64x2> for u8x2
impl From<m64x2> for u8x2
impl From<f32x2> for u8x2
impl From<u32x2> for u8x2
impl From<i32x2> for u8x2
impl From<m32x2> for u8x2
impl From<u16x2> for u8x2
impl From<m16x2> for u8x2
impl From<i8x2> for u8x2
impl From<m8x2> for u8x2
impl From<m64x2> for m8x2
impl From<m32x2> for m8x2
impl From<m16x2> for m8x2
impl From<u64x4> for f64x4
impl From<i64x4> for f64x4
impl From<m64x4> for f64x4
impl From<u32x4> for f64x4
impl From<i32x4> for f64x4
impl From<f32x4> for f64x4
impl From<m32x4> for f64x4
impl From<u16x4> for f64x4
impl From<i16x4> for f64x4
impl From<m16x4> for f64x4
impl From<u8x4> for f64x4
impl From<i8x4> for f64x4
impl From<m8x4> for f64x4
impl From<u64x4> for i64x4
impl From<f64x4> for i64x4
impl From<m64x4> for i64x4
impl From<u32x4> for i64x4
impl From<i32x4> for i64x4
impl From<f32x4> for i64x4
impl From<m32x4> for i64x4
impl From<u16x4> for i64x4
impl From<i16x4> for i64x4
impl From<m16x4> for i64x4
impl From<u8x4> for i64x4
impl From<i8x4> for i64x4
impl From<m8x4> for i64x4
impl From<i64x4> for u64x4
impl From<f64x4> for u64x4
impl From<m64x4> for u64x4
impl From<u32x4> for u64x4
impl From<i32x4> for u64x4
impl From<f32x4> for u64x4
impl From<m32x4> for u64x4
impl From<u16x4> for u64x4
impl From<i16x4> for u64x4
impl From<m16x4> for u64x4
impl From<u8x4> for u64x4
impl From<i8x4> for u64x4
impl From<m8x4> for u64x4
impl From<u64x8> for f32x8
impl From<i64x8> for f32x8
impl From<f64x8> for f32x8
impl From<m1x8> for f32x8
impl From<u32x8> for f32x8
impl From<i32x8> for f32x8
impl From<m32x8> for f32x8
impl From<u16x8> for f32x8
impl From<i16x8> for f32x8
impl From<m16x8> for f32x8
impl From<u8x8> for f32x8
impl From<i8x8> for f32x8
impl From<m8x8> for f32x8
impl From<u64x8> for i32x8
impl From<i64x8> for i32x8
impl From<f64x8> for i32x8
impl From<m1x8> for i32x8
impl From<u32x8> for i32x8
impl From<f32x8> for i32x8
impl From<m32x8> for i32x8
impl From<u16x8> for i32x8
impl From<i16x8> for i32x8
impl From<m16x8> for i32x8
impl From<u8x8> for i32x8
impl From<i8x8> for i32x8
impl From<m8x8> for i32x8
impl From<u64x8> for u32x8
impl From<i64x8> for u32x8
impl From<f64x8> for u32x8
impl From<m1x8> for u32x8
impl From<i32x8> for u32x8
impl From<f32x8> for u32x8
impl From<m32x8> for u32x8
impl From<u16x8> for u32x8
impl From<i16x8> for u32x8
impl From<m16x8> for u32x8
impl From<u8x8> for u32x8
impl From<i8x8> for u32x8
impl From<m8x8> for u32x8
impl From<u32x16> for i16x16
impl From<i32x16> for i16x16
impl From<f32x16> for i16x16
impl From<m1x16> for i16x16
impl From<u16x16> for i16x16
impl From<m16x16> for i16x16
impl From<u8x16> for i16x16
impl From<i8x16> for i16x16
impl From<m8x16> for i16x16
impl From<u32x16> for u16x16
impl From<i32x16> for u16x16
impl From<f32x16> for u16x16
impl From<m1x16> for u16x16
impl From<i16x16> for u16x16
impl From<m16x16> for u16x16
impl From<u8x16> for u16x16
impl From<i8x16> for u16x16
impl From<m8x16> for u16x16
impl From<u16x32> for i8x32
impl From<i16x32> for i8x32
impl From<u8x32> for i8x32
impl From<m8x32> for i8x32
impl From<u16x32> for u8x32
impl From<i16x32> for u8x32
impl From<i8x32> for u8x32
impl From<m8x32> for u8x32
impl From<m1x32> for m8x32
impl From<m1x16> for m16x16
impl From<m8x16> for m16x16
impl From<m1x8> for m32x8
impl From<m16x8> for m32x8
impl From<m8x8> for m32x8
impl From<m32x4> for m64x4
impl From<m16x4> for m64x4
impl From<m8x4> for m64x4
impl From<f64x2> for i16x2
impl From<u64x2> for i16x2
impl From<i64x2> for i16x2
impl From<m64x2> for i16x2
impl From<f32x2> for i16x2
impl From<u32x2> for i16x2
impl From<i32x2> for i16x2
impl From<m32x2> for i16x2
impl From<u16x2> for i16x2
impl From<m16x2> for i16x2
impl From<u8x2> for i16x2
impl From<i8x2> for i16x2
impl From<m8x2> for i16x2
impl From<f64x2> for u16x2
impl From<u64x2> for u16x2
impl From<i64x2> for u16x2
impl From<m64x2> for u16x2
impl From<f32x2> for u16x2
impl From<u32x2> for u16x2
impl From<i32x2> for u16x2
impl From<m32x2> for u16x2
impl From<i16x2> for u16x2
impl From<m16x2> for u16x2
impl From<u8x2> for u16x2
impl From<i8x2> for u16x2
impl From<m8x2> for u16x2
impl From<f64x4> for i8x4
impl From<u64x4> for i8x4
impl From<i64x4> for i8x4
impl From<m64x4> for i8x4
impl From<u32x4> for i8x4
impl From<i32x4> for i8x4
impl From<f32x4> for i8x4
impl From<m32x4> for i8x4
impl From<u16x4> for i8x4
impl From<i16x4> for i8x4
impl From<m16x4> for i8x4
impl From<u8x4> for i8x4
impl From<m8x4> for i8x4
impl From<f64x4> for u8x4
impl From<u64x4> for u8x4
impl From<i64x4> for u8x4
impl From<m64x4> for u8x4
impl From<u32x4> for u8x4
impl From<i32x4> for u8x4
impl From<f32x4> for u8x4
impl From<m32x4> for u8x4
impl From<u16x4> for u8x4
impl From<i16x4> for u8x4
impl From<m16x4> for u8x4
impl From<i8x4> for u8x4
impl From<m8x4> for u8x4
impl From<m64x4> for m8x4
impl From<m32x4> for m8x4
impl From<m16x4> for m8x4
impl From<m64x2> for m16x2
impl From<m32x2> for m16x2
impl From<m8x2> for m16x2
impl From<u64x8> for f64x8
impl From<i64x8> for f64x8
impl From<m1x8> for f64x8
impl From<u32x8> for f64x8
impl From<i32x8> for f64x8
impl From<f32x8> for f64x8
impl From<m32x8> for f64x8
impl From<u16x8> for f64x8
impl From<i16x8> for f64x8
impl From<m16x8> for f64x8
impl From<u8x8> for f64x8
impl From<i8x8> for f64x8
impl From<m8x8> for f64x8
impl From<u64x8> for i64x8
impl From<f64x8> for i64x8
impl From<m1x8> for i64x8
impl From<u32x8> for i64x8
impl From<i32x8> for i64x8
impl From<f32x8> for i64x8
impl From<m32x8> for i64x8
impl From<u16x8> for i64x8
impl From<i16x8> for i64x8
impl From<m16x8> for i64x8
impl From<u8x8> for i64x8
impl From<i8x8> for i64x8
impl From<m8x8> for i64x8
impl From<i64x8> for u64x8
impl From<f64x8> for u64x8
impl From<m1x8> for u64x8
impl From<u32x8> for u64x8
impl From<i32x8> for u64x8
impl From<f32x8> for u64x8
impl From<m32x8> for u64x8
impl From<u16x8> for u64x8
impl From<i16x8> for u64x8
impl From<m16x8> for u64x8
impl From<u8x8> for u64x8
impl From<i8x8> for u64x8
impl From<m8x8> for u64x8
impl From<u32x16> for f32x16
impl From<i32x16> for f32x16
impl From<m1x16> for f32x16
impl From<u16x16> for f32x16
impl From<i16x16> for f32x16
impl From<m16x16> for f32x16
impl From<u8x16> for f32x16
impl From<i8x16> for f32x16
impl From<m8x16> for f32x16
impl From<u32x16> for i32x16
impl From<f32x16> for i32x16
impl From<m1x16> for i32x16
impl From<u16x16> for i32x16
impl From<i16x16> for i32x16
impl From<m16x16> for i32x16
impl From<u8x16> for i32x16
impl From<i8x16> for i32x16
impl From<m8x16> for i32x16
impl From<i32x16> for u32x16
impl From<f32x16> for u32x16
impl From<m1x16> for u32x16
impl From<u16x16> for u32x16
impl From<i16x16> for u32x16
impl From<m16x16> for u32x16
impl From<u8x16> for u32x16
impl From<i8x16> for u32x16
impl From<m8x16> for u32x16
impl From<u16x32> for i16x32
impl From<u8x32> for i16x32
impl From<i8x32> for i16x32
impl From<m1x32> for i16x32
impl From<m8x32> for i16x32
impl From<i16x32> for u16x32
impl From<u8x32> for u16x32
impl From<i8x32> for u16x32
impl From<m1x32> for u16x32
impl From<m8x32> for u16x32
impl From<u8x64> for i8x64
impl From<m1x64> for i8x64
impl From<i8x64> for u8x64
impl From<m1x64> for u8x64
impl From<m8x32> for m1x32
impl From<m16x16> for m1x16
impl From<m8x16> for m1x16
impl From<m32x8> for m1x8
impl From<m16x8> for m1x8
impl From<m8x8> for m1x8
impl From<f64x2> for f32x2
impl From<u64x2> for f32x2
impl From<i64x2> for f32x2
impl From<m64x2> for f32x2
impl From<u32x2> for f32x2
impl From<i32x2> for f32x2
impl From<m32x2> for f32x2
impl From<u16x2> for f32x2
impl From<i16x2> for f32x2
impl From<m16x2> for f32x2
impl From<u8x2> for f32x2
impl From<i8x2> for f32x2
impl From<m8x2> for f32x2
impl From<f64x2> for u32x2
impl From<u64x2> for u32x2
impl From<i64x2> for u32x2
impl From<m64x2> for u32x2
impl From<f32x2> for u32x2
impl From<i32x2> for u32x2
impl From<m32x2> for u32x2
impl From<u16x2> for u32x2
impl From<i16x2> for u32x2
impl From<m16x2> for u32x2
impl From<u8x2> for u32x2
impl From<i8x2> for u32x2
impl From<m8x2> for u32x2
impl From<f64x2> for i32x2
impl From<u64x2> for i32x2
impl From<i64x2> for i32x2
impl From<m64x2> for i32x2
impl From<f32x2> for i32x2
impl From<u32x2> for i32x2
impl From<m32x2> for i32x2
impl From<u16x2> for i32x2
impl From<i16x2> for i32x2
impl From<m16x2> for i32x2
impl From<u8x2> for i32x2
impl From<i8x2> for i32x2
impl From<m8x2> for i32x2
impl From<f64x4> for u16x4
impl From<u64x4> for u16x4
impl From<i64x4> for u16x4
impl From<m64x4> for u16x4
impl From<f32x4> for u16x4
impl From<i32x4> for u16x4
impl From<u32x4> for u16x4
impl From<m32x4> for u16x4
impl From<i16x4> for u16x4
impl From<m16x4> for u16x4
impl From<u8x4> for u16x4
impl From<i8x4> for u16x4
impl From<m8x4> for u16x4
impl From<f64x4> for i16x4
impl From<u64x4> for i16x4
impl From<i64x4> for i16x4
impl From<m64x4> for i16x4
impl From<f32x4> for i16x4
impl From<i32x4> for i16x4
impl From<u32x4> for i16x4
impl From<m32x4> for i16x4
impl From<u16x4> for i16x4
impl From<m16x4> for i16x4
impl From<u8x4> for i16x4
impl From<i8x4> for i16x4
impl From<m8x4> for i16x4
impl From<f64x8> for i8x8
impl From<u64x8> for i8x8
impl From<i64x8> for i8x8
impl From<m1x8> for i8x8
impl From<f32x8> for i8x8
impl From<u32x8> for i8x8
impl From<i32x8> for i8x8
impl From<m32x8> for i8x8
impl From<i16x8> for i8x8
impl From<u16x8> for i8x8
impl From<m16x8> for i8x8
impl From<u8x8> for i8x8
impl From<m8x8> for i8x8
impl From<f64x8> for u8x8
impl From<u64x8> for u8x8
impl From<i64x8> for u8x8
impl From<m1x8> for u8x8
impl From<f32x8> for u8x8
impl From<u32x8> for u8x8
impl From<i32x8> for u8x8
impl From<m32x8> for u8x8
impl From<i16x8> for u8x8
impl From<u16x8> for u8x8
impl From<m16x8> for u8x8
impl From<i8x8> for u8x8
impl From<m8x8> for u8x8
impl From<m1x8> for m8x8
impl From<m32x8> for m8x8
impl From<m16x8> for m8x8
impl From<m64x4> for m16x4
impl From<m32x4> for m16x4
impl From<m8x4> for m16x4
impl From<m64x2> for m32x2
impl From<m16x2> for m32x2
impl From<m8x2> for m32x2