Trait sgx_tstd::convert::From 1.0.0[−][src]
pub trait From<T> { fn from(T) -> Self; }
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);
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) }
Required Methods
fn from(T) -> Self
Performs the conversion.
Implementations on Foreign Types
impl From<LocalWaker> for Waker
[src]
impl From<LocalWaker> for Waker
fn from(local_waker: LocalWaker) -> Waker
[src]
fn from(local_waker: LocalWaker) -> Waker
impl<T> From<T> for Poll<T>
[src]
impl<T> From<T> for Poll<T>
impl<'a, T> From<FutureObj<'a, T>> for LocalFutureObj<'a, T>
[src]
impl<'a, T> From<FutureObj<'a, T>> for LocalFutureObj<'a, T>
fn from(f: FutureObj<'a, T>) -> LocalFutureObj<'a, T>
[src]
fn from(f: FutureObj<'a, T>) -> LocalFutureObj<'a, T>
impl<'a, F> From<Box<F>> for LocalFutureObj<'a, ()> where
F: 'a + Future<Output = ()>,
[src]
impl<'a, F> From<Box<F>> for LocalFutureObj<'a, ()> where
F: 'a + Future<Output = ()>,
fn from(boxed: Box<F>) -> LocalFutureObj<'a, ()>
[src]
fn from(boxed: Box<F>) -> LocalFutureObj<'a, ()>
impl<T> From<Arc<T>> for Waker where
T: Wake + 'static,
[src]
impl<T> From<Arc<T>> for Waker where
T: Wake + 'static,
impl<'a, F> From<PinBox<F>> for FutureObj<'a, ()> where
F: 'a + Send + Future<Output = ()>,
[src]
impl<'a, F> From<PinBox<F>> for FutureObj<'a, ()> where
F: 'a + Send + Future<Output = ()>,
impl<'a, F> From<Box<F>> for FutureObj<'a, ()> where
F: 'a + Send + Future<Output = ()>,
[src]
impl<'a, F> From<Box<F>> for FutureObj<'a, ()> where
F: 'a + Send + Future<Output = ()>,
impl<'a, F> From<PinBox<F>> for LocalFutureObj<'a, ()> where
F: 'a + Future<Output = ()>,
[src]
impl<'a, F> From<PinBox<F>> for LocalFutureObj<'a, ()> where
F: 'a + Future<Output = ()>,
fn from(boxed: PinBox<F>) -> LocalFutureObj<'a, ()>
[src]
fn from(boxed: PinBox<F>) -> LocalFutureObj<'a, ()>
Implementors
impl From<bool> for AtomicBool
impl From<u8> for usize
impl From<f32> for f64
impl From<bool> for u16
impl From<u8> for u64
impl From<bool> for u32
impl From<u16> for u128
impl From<u8> for isize
impl From<u16> for f64
impl From<i64> for i128
impl<'a, T> From<&'a T> for NonNull<T> where
T: ?Sized,impl From<u8> for u32
impl From<!> for TryFromIntError
impl From<u32> for AtomicU32
impl From<u32> for i64
impl From<u16> for u32
impl From<u8> for i128
impl From<i16> for i64
impl From<i16> for f64
impl From<u8> for AtomicU8
impl From<u8> for u16
impl From<i32> for i128
impl From<i8> for i32
impl From<u16> for i128
impl From<u64> for u128
impl From<i32> for i64
impl From<bool> for i128
impl From<i8> for isize
impl From<i64> for AtomicI64
impl From<char> for u32
impl From<u8> for char
impl From<u8> for f32
impl<T> From<T> for UnsafeCell<T>
impl From<bool> for i64
impl From<u8> for i32
impl From<bool> for u8
impl From<i16> for f32
impl<T> From<T> for Cell<T>
impl From<u16> for usize
impl From<i32> for AtomicI32
impl<T> From<T> for RefCell<T>
impl From<u8> for i16
impl From<i16> for AtomicI16
impl From<u32> for u64
impl From<u16> for i64
impl From<u8> for u128
impl From<u8> for f64
impl From<u16> for u64
impl<'a, T> From<&'a mut T> for NonNull<T> where
T: ?Sized,impl<T> From<Unique<T>> for NonNull<T> where
T: ?Sized,impl From<u16> for AtomicU16
impl<T> From<T> for Option<T>
impl From<usize> for AtomicUsize
impl From<i8> for f32
impl From<bool> for i32
impl From<u32> for i128
impl<T> From<*mut T> for AtomicPtr<T>
impl From<bool> for i16
impl From<isize> for AtomicIsize
impl From<bool> for usize
impl From<u32> for f64
impl From<bool> for u128
impl From<i8> for i16
impl From<i32> for f64
impl From<bool> for isize
impl From<u16> for f32
impl From<u16> for i32
impl From<u32> for u128
impl From<bool> for u64
impl From<u8> for i64
impl<T> From<T> for T
impl From<i8> for f64
impl From<u64> for AtomicU64
impl From<i16> for isize
impl From<i8> for i64
impl From<u64> for i128
impl From<bool> for i8
impl From<i8> for i128
impl From<i16> for i128
impl From<i8> for AtomicI8
impl From<i16> for i32
impl<T> From<T> for Arc<T>
impl<T> From<Vec<T>> for Box<[T]>
impl<'a, T> From<&'a [T]> for Box<[T]> where
T: Copy,impl<'a, T> From<&'a mut [T]> for Vec<T> where
T: Clone,impl<'a> From<&'a str> for Arc<str>
impl<'a> From<&'a str> for Box<str>
impl<'a> From<String> for Cow<'a, str>
impl<'a> From<&'a str> for Rc<str>
impl<T> From<Box<[T]>> for Vec<T>
impl From<Box<str>> for String
impl<T> From<Box<T>> for Arc<T> where
T: ?Sized,impl<'a> From<&'a str> for Vec<u8>
impl<T> From<Box<T>> for PinBox<T> where
T: ?Sized,impl From<LayoutErr> for CollectionAllocErr
impl<'a, T> From<&'a [T]> for Vec<T> where
T: Clone,impl<T> From<Vec<T>> for Arc<[T]>
impl From<String> for Arc<str>
impl<'a, T> From<&'a [T]> for Rc<[T]> where
T: Clone,impl<T> From<VecDeque<T>> for Vec<T>
impl<'a> From<Cow<'a, str>> for String
impl From<Box<str>> for Box<[u8]>
impl<T> From<Vec<T>> for BinaryHeap<T> where
T: Ord,impl<T> From<T> for Box<T>
impl From<String> for Box<str>
impl<'a> From<&'a str> for Cow<'a, str>
impl<'a, T> From<&'a [T]> for Arc<[T]> where
T: Clone,impl<'a, T> From<Vec<T>> for Cow<'a, [T]> where
T: Clone,impl<T> From<PinBox<T>> for Box<T> where
T: Unpin + ?Sized,impl<T> From<BinaryHeap<T>> for Vec<T>
impl<'a, T> From<&'a [T]> for Cow<'a, [T]> where
T: Clone,impl<T> From<Box<T>> for Rc<T> where
T: ?Sized,impl<T> From<Vec<T>> for Rc<[T]>
impl<T> From<Vec<T>> for VecDeque<T>
impl<'a, T> From<&'a Vec<T>> for Cow<'a, [T]> where
T: Clone,impl<'a> From<&'a String> for Cow<'a, str>
impl<'a> From<&'a str> for String
impl From<String> for Rc<str>
impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where
[T]: ToOwned,
<[T] as ToOwned>::Owned == Vec<T>,impl<T> From<T> for Rc<T>
impl From<AllocErr> for CollectionAllocErr
impl From<String> for Vec<u8>
impl<'a> From<&'a CStr> for Arc<CStr>
impl From<CString> for Box<CStr>
impl From<Box<CStr>> for CString
impl From<CString> for Rc<CStr>
impl<'a> From<&'a CStr> for Box<CStr>
impl<'a> From<&'a CStr> for Rc<CStr>
impl From<CString> for Arc<CStr>
impl<'a> From<&'a CStr> for CString
impl From<CString> for Vec<u8>
impl<'a, E: Error + 'a> From<E> for Box<Error + 'a>
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<Error + Send + Sync + 'a>
impl From<String> for Box<Error + Send + Sync>
impl From<String> for Box<Error>
impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a>
impl<'a> From<&'a str> for Box<Error>
impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a>
impl<'a> From<Cow<'a, str>> for Box<Error>
impl From<NulError> for Error
impl From<String> for OsString
impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for OsString
impl<'a> From<&'a OsStr> for Box<OsStr>
impl From<Box<OsStr>> for OsString
impl From<OsString> for Box<OsStr>
impl From<OsString> for Arc<OsStr>
impl<'a> From<&'a OsStr> for Arc<OsStr>
impl From<OsString> for Rc<OsStr>
impl<'a> From<&'a OsStr> for Rc<OsStr>
impl<W> From<IntoInnerError<W>> for Error
impl From<ErrorKind> for Error
impl From<sgx_status_t> for Error
impl From<Ipv4Addr> for IpAddr
impl From<Ipv6Addr> for IpAddr
impl From<Ipv4Addr> for u32
impl From<u32> for Ipv4Addr
impl From<[u8; 4]> for Ipv4Addr
impl From<[u8; 4]> for IpAddr
impl From<Ipv6Addr> for u128
impl From<u128> for Ipv6Addr
impl From<[u8; 16]> for Ipv6Addr
impl From<[u16; 8]> for Ipv6Addr
impl From<[u8; 16]> for IpAddr
impl From<[u16; 8]> for IpAddr
impl From<SocketAddrV4> for SocketAddr
impl From<SocketAddrV6> for SocketAddr
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr
impl<'a> From<&'a Path> for Box<Path>
impl From<Box<Path>> for PathBuf
impl From<PathBuf> for Box<Path>
impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for PathBuf
impl From<OsString> for PathBuf
impl From<PathBuf> for OsString
impl From<String> for PathBuf
impl<'a> From<&'a Path> for Cow<'a, Path>
impl<'a> From<PathBuf> for Cow<'a, Path>
impl From<PathBuf> for Arc<Path>
impl<'a> From<&'a Path> for Arc<Path>
impl From<PathBuf> for Rc<Path>
impl<'a> From<&'a Path> for Rc<Path>
impl<T> From<T> for SgxMutex<T>
impl<T> From<T> for SgxRwLock<T>
impl<T> From<PoisonError<T>> for TryLockError<T>