Trait std::convert::From 1.0.0[−][src]
pub trait From<T> { pub fn from(T) -> Self; }
Used to do value-to-value conversions while consuming the input value. It is the reciprocal of
Into
.
One should always prefer implementing From
over Into
because implementing From
automatically provides one with an implementation of Into
thanks to the blanket implementation in the standard library.
Only implement Into
when targeting a version prior to Rust 1.41 and converting to a type
outside the current crate.
From
was not able to do these types of conversions in earlier versions because of Rust’s
orphaning rules.
See Into
for more details.
Prefer using Into
over using From
when specifying trait bounds on a generic function.
This way, types that directly implement Into
can be used as arguments as well.
The From
is also very useful when performing error handling. When constructing a function
that is capable of failing, the return type will generally be of the form Result<T, E>
.
The From
trait simplifies error handling by allowing a function to return a single error type
that encapsulate multiple error types. See the “Examples” section and the book for more
details.
Note: This trait must not fail. If the conversion can fail, use TryFrom
.
Generic Implementations
From<T> for U
impliesInto
<U> for T
From
is reflexive, which means thatFrom<T> for T
is implemented
Examples
String
implements From<&str>
:
An explicit conversion from a &str
to a String is done as follows:
let string = "hello".to_string(); let other_string = String::from("hello"); assert_eq!(string, other_string);Run
While performing error handling it is often useful to implement From
for your own error type.
By converting underlying error types to our own custom error type that encapsulates the
underlying error type, we can return a single error type without losing information on the
underlying cause. The ‘?’ operator automatically converts the underlying error type to our
custom error type by calling Into<CliError>::into
which is automatically provided when
implementing From
. The compiler then infers which implementation of Into
should be used.
use std::fs; use std::io; 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 contents = fs::read_to_string(&file_name)?; let num: i32 = contents.trim().parse()?; Ok(num) }Run
Required methods
Loading content...Implementors
impl From<&'_ str> for Box<dyn Error>
1.6.0[src]
impl From<&'_ str> for Box<dyn Error>
1.6.0[src]fn from(err: &str) -> Box<dyn Error>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<&'_ CStr> for Box<CStr>
1.17.0[src]
impl From<&'_ CStr> for Box<CStr>
1.17.0[src]fn from(s: &CStr) -> Box<CStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<&'_ OsStr> for Box<OsStr>
1.17.0[src]
impl From<&'_ OsStr> for Box<OsStr>
1.17.0[src]fn from(s: &OsStr) -> Box<OsStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<&'_ Path> for Box<Path>
1.17.0[src]
impl From<&'_ Path> for Box<Path>
1.17.0[src]fn from(path: &Path) -> Box<Path>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<Cow<'_, CStr>> for Box<CStr>
1.45.0[src]
impl From<Cow<'_, CStr>> for Box<CStr>
1.45.0[src]fn from(cow: Cow<'_, CStr>) -> Box<CStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<Cow<'_, OsStr>> for Box<OsStr>
1.45.0[src]
impl From<Cow<'_, OsStr>> for Box<OsStr>
1.45.0[src]fn from(cow: Cow<'_, OsStr>) -> Box<OsStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<Cow<'_, Path>> for Box<Path>
1.45.0[src]
impl From<Cow<'_, Path>> for Box<Path>
1.45.0[src]fn from(cow: Cow<'_, Path>) -> Box<Path>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<ErrorKind> for Error
1.14.0[src]
impl From<ErrorKind> for Error
1.14.0[src]Intended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.
impl From<Infallible> for TryFromSliceError
1.36.0[src]
impl From<Infallible> for TryFromSliceError
1.36.0[src]pub fn from(x: Infallible) -> TryFromSliceError
[src]
impl From<Infallible> for TryFromIntError
1.34.0[src]
impl From<Infallible> for TryFromIntError
1.34.0[src]pub fn from(x: Infallible) -> TryFromIntError
[src]
impl From<[u8; 16]> for IpAddr
1.17.0[src]
impl From<[u8; 16]> for IpAddr
1.17.0[src]fn from(octets: [u8; 16]) -> IpAddr
[src]
Creates an IpAddr::V6
from a sixteen element byte array.
Examples
use std::net::{IpAddr, Ipv6Addr}; let addr = IpAddr::from([ 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8, 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8, ]); assert_eq!( IpAddr::V6(Ipv6Addr::new( 0x1918, 0x1716, 0x1514, 0x1312, 0x1110, 0x0f0e, 0x0d0c, 0x0b0a )), addr );Run
impl From<[u8; 16]> for Ipv6Addr
1.9.0[src]
impl From<[u8; 16]> for Ipv6Addr
1.9.0[src]fn from(octets: [u8; 16]) -> Ipv6Addr
[src]
Creates an Ipv6Addr
from a sixteen element byte array.
Examples
use std::net::Ipv6Addr; let addr = Ipv6Addr::from([ 25u8, 24u8, 23u8, 22u8, 21u8, 20u8, 19u8, 18u8, 17u8, 16u8, 15u8, 14u8, 13u8, 12u8, 11u8, 10u8, ]); assert_eq!( Ipv6Addr::new( 0x1918, 0x1716, 0x1514, 0x1312, 0x1110, 0x0f0e, 0x0d0c, 0x0b0a ), addr );Run
impl From<[u16; 8]> for IpAddr
1.17.0[src]
impl From<[u16; 8]> for IpAddr
1.17.0[src]fn from(segments: [u16; 8]) -> IpAddr
[src]
Creates an IpAddr::V6
from an eight element 16-bit array.
Examples
use std::net::{IpAddr, Ipv6Addr}; let addr = IpAddr::from([ 525u16, 524u16, 523u16, 522u16, 521u16, 520u16, 519u16, 518u16, ]); assert_eq!( IpAddr::V6(Ipv6Addr::new( 0x20d, 0x20c, 0x20b, 0x20a, 0x209, 0x208, 0x207, 0x206 )), addr );Run
impl From<bool> for AtomicBool
1.24.0[src]
impl From<bool> for AtomicBool
1.24.0[src]impl From<i128> for AtomicI128
[src]
impl From<i128> for AtomicI128
[src]pub fn from(v: i128) -> AtomicI128
[src]
Converts an i128
into an AtomicI128
.
impl From<isize> for AtomicIsize
1.23.0[src]
impl From<isize> for AtomicIsize
1.23.0[src]pub fn from(v: isize) -> AtomicIsize
[src]
Converts an isize
into an AtomicIsize
.
impl From<!> for Infallible
1.34.0[src]
impl From<!> for Infallible
1.34.0[src]pub fn from(x: !) -> Infallible
[src]
impl From<!> for TryFromIntError
[src]
impl From<!> for TryFromIntError
[src]pub fn from(never: !) -> TryFromIntError
[src]
impl From<u8> for char
1.13.0[src]
impl From<u8> for char
1.13.0[src]Maps a byte in 0x00..=0xFF to a char
whose code point has the same value, in U+0000..=U+00FF.
Unicode is designed such that this effectively decodes bytes with the character encoding that IANA calls ISO-8859-1. This encoding is compatible with ASCII.
Note that this is different from ISO/IEC 8859-1 a.k.a. ISO 8859-1 (with one less hyphen), which leaves some “blanks”, byte values that are not assigned to any character. ISO-8859-1 (the IANA one) assigns them to the C0 and C1 control codes.
Note that this is also different from Windows-1252 a.k.a. code page 1252, which is a superset ISO/IEC 8859-1 that assigns some (not all!) blanks to punctuation and various Latin characters.
To confuse things further, on the Web
ascii
, iso-8859-1
, and windows-1252
are all aliases
for a superset of Windows-1252 that fills the remaining blanks with corresponding
C0 and C1 control codes.
impl From<u128> for AtomicU128
[src]
impl From<u128> for AtomicU128
[src]pub fn from(v: u128) -> AtomicU128
[src]
Converts an u128
into an AtomicU128
.
impl From<usize> for AtomicUsize
1.23.0[src]
impl From<usize> for AtomicUsize
1.23.0[src]pub fn from(v: usize) -> AtomicUsize
[src]
Converts an usize
into an AtomicUsize
.
impl From<LayoutError> for TryReserveError
[src]
impl From<LayoutError> for TryReserveError
[src]pub fn from(LayoutError) -> TryReserveError
[src]
impl From<CString> for Box<CStr>
1.20.0[src]
impl From<CString> for Box<CStr>
1.20.0[src]fn from(s: CString) -> Box<CStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<OsString> for Box<OsStr>
1.20.0[src]
impl From<OsString> for Box<OsStr>
1.20.0[src]fn from(s: OsString) -> Box<OsStr>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<File> for Stdio
1.20.0[src]
impl From<File> for Stdio
1.20.0[src]fn from(file: File) -> Stdio
[src]
Converts a File
into a Stdio
Examples
File
will be converted to Stdio
using Stdio::from
under the hood.
use std::fs::File; use std::process::Command; // With the `foo.txt` file containing `Hello, world!" let file = File::open("foo.txt").unwrap(); let reverse = Command::new("rev") .stdin(file) // Implicit File conversion into a Stdio .output() .expect("failed reverse command"); assert_eq!(reverse.stdout, b"!dlrow ,olleH");Run
impl From<SocketAddrV4> for SocketAddr
1.16.0[src]
impl From<SocketAddrV4> for SocketAddr
1.16.0[src]fn from(sock4: SocketAddrV4) -> SocketAddr
[src]
Converts a SocketAddrV4
into a SocketAddr::V4
.
impl From<SocketAddrV6> for SocketAddr
1.16.0[src]
impl From<SocketAddrV6> for SocketAddr
1.16.0[src]fn from(sock6: SocketAddrV6) -> SocketAddr
[src]
Converts a SocketAddrV6
into a SocketAddr::V6
.
impl From<NonZeroI8> for NonZeroI16
1.41.0[src]
impl From<NonZeroI8> for NonZeroI16
1.41.0[src]pub fn from(small: NonZeroI8) -> NonZeroI16
[src]
Converts NonZeroI8
to NonZeroI16
losslessly.
impl From<NonZeroI8> for NonZeroI32
1.41.0[src]
impl From<NonZeroI8> for NonZeroI32
1.41.0[src]pub fn from(small: NonZeroI8) -> NonZeroI32
[src]
Converts NonZeroI8
to NonZeroI32
losslessly.
impl From<NonZeroI8> for NonZeroI64
1.41.0[src]
impl From<NonZeroI8> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroI8) -> NonZeroI64
[src]
Converts NonZeroI8
to NonZeroI64
losslessly.
impl From<NonZeroI8> for NonZeroI128
1.41.0[src]
impl From<NonZeroI8> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroI8) -> NonZeroI128
[src]
Converts NonZeroI8
to NonZeroI128
losslessly.
impl From<NonZeroI8> for NonZeroIsize
1.41.0[src]
impl From<NonZeroI8> for NonZeroIsize
1.41.0[src]pub fn from(small: NonZeroI8) -> NonZeroIsize
[src]
Converts NonZeroI8
to NonZeroIsize
losslessly.
impl From<NonZeroI16> for i16
1.31.0[src]
impl From<NonZeroI16> for i16
1.31.0[src]pub fn from(nonzero: NonZeroI16) -> i16
[src]
Converts a NonZeroI16
into an i16
impl From<NonZeroI16> for NonZeroI32
1.41.0[src]
impl From<NonZeroI16> for NonZeroI32
1.41.0[src]pub fn from(small: NonZeroI16) -> NonZeroI32
[src]
Converts NonZeroI16
to NonZeroI32
losslessly.
impl From<NonZeroI16> for NonZeroI64
1.41.0[src]
impl From<NonZeroI16> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroI16) -> NonZeroI64
[src]
Converts NonZeroI16
to NonZeroI64
losslessly.
impl From<NonZeroI16> for NonZeroI128
1.41.0[src]
impl From<NonZeroI16> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroI16) -> NonZeroI128
[src]
Converts NonZeroI16
to NonZeroI128
losslessly.
impl From<NonZeroI16> for NonZeroIsize
1.41.0[src]
impl From<NonZeroI16> for NonZeroIsize
1.41.0[src]pub fn from(small: NonZeroI16) -> NonZeroIsize
[src]
Converts NonZeroI16
to NonZeroIsize
losslessly.
impl From<NonZeroI32> for i32
1.31.0[src]
impl From<NonZeroI32> for i32
1.31.0[src]pub fn from(nonzero: NonZeroI32) -> i32
[src]
Converts a NonZeroI32
into an i32
impl From<NonZeroI32> for NonZeroI64
1.41.0[src]
impl From<NonZeroI32> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroI32) -> NonZeroI64
[src]
Converts NonZeroI32
to NonZeroI64
losslessly.
impl From<NonZeroI32> for NonZeroI128
1.41.0[src]
impl From<NonZeroI32> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroI32) -> NonZeroI128
[src]
Converts NonZeroI32
to NonZeroI128
losslessly.
impl From<NonZeroI64> for i64
1.31.0[src]
impl From<NonZeroI64> for i64
1.31.0[src]pub fn from(nonzero: NonZeroI64) -> i64
[src]
Converts a NonZeroI64
into an i64
impl From<NonZeroI64> for NonZeroI128
1.41.0[src]
impl From<NonZeroI64> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroI64) -> NonZeroI128
[src]
Converts NonZeroI64
to NonZeroI128
losslessly.
impl From<NonZeroI128> for i128
1.31.0[src]
impl From<NonZeroI128> for i128
1.31.0[src]pub fn from(nonzero: NonZeroI128) -> i128
[src]
Converts a NonZeroI128
into an i128
impl From<NonZeroIsize> for isize
1.31.0[src]
impl From<NonZeroIsize> for isize
1.31.0[src]pub fn from(nonzero: NonZeroIsize) -> isize
[src]
Converts a NonZeroIsize
into an isize
impl From<NonZeroU8> for NonZeroI16
1.41.0[src]
impl From<NonZeroU8> for NonZeroI16
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroI16
[src]
Converts NonZeroU8
to NonZeroI16
losslessly.
impl From<NonZeroU8> for NonZeroI32
1.41.0[src]
impl From<NonZeroU8> for NonZeroI32
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroI32
[src]
Converts NonZeroU8
to NonZeroI32
losslessly.
impl From<NonZeroU8> for NonZeroI64
1.41.0[src]
impl From<NonZeroU8> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroI64
[src]
Converts NonZeroU8
to NonZeroI64
losslessly.
impl From<NonZeroU8> for NonZeroI128
1.41.0[src]
impl From<NonZeroU8> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroI128
[src]
Converts NonZeroU8
to NonZeroI128
losslessly.
impl From<NonZeroU8> for NonZeroIsize
1.41.0[src]
impl From<NonZeroU8> for NonZeroIsize
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroIsize
[src]
Converts NonZeroU8
to NonZeroIsize
losslessly.
impl From<NonZeroU8> for NonZeroU16
1.41.0[src]
impl From<NonZeroU8> for NonZeroU16
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroU16
[src]
Converts NonZeroU8
to NonZeroU16
losslessly.
impl From<NonZeroU8> for NonZeroU32
1.41.0[src]
impl From<NonZeroU8> for NonZeroU32
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroU32
[src]
Converts NonZeroU8
to NonZeroU32
losslessly.
impl From<NonZeroU8> for NonZeroU64
1.41.0[src]
impl From<NonZeroU8> for NonZeroU64
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroU64
[src]
Converts NonZeroU8
to NonZeroU64
losslessly.
impl From<NonZeroU8> for NonZeroU128
1.41.0[src]
impl From<NonZeroU8> for NonZeroU128
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroU128
[src]
Converts NonZeroU8
to NonZeroU128
losslessly.
impl From<NonZeroU8> for NonZeroUsize
1.41.0[src]
impl From<NonZeroU8> for NonZeroUsize
1.41.0[src]pub fn from(small: NonZeroU8) -> NonZeroUsize
[src]
Converts NonZeroU8
to NonZeroUsize
losslessly.
impl From<NonZeroU16> for u16
1.31.0[src]
impl From<NonZeroU16> for u16
1.31.0[src]pub fn from(nonzero: NonZeroU16) -> u16
[src]
Converts a NonZeroU16
into an u16
impl From<NonZeroU16> for NonZeroI32
1.41.0[src]
impl From<NonZeroU16> for NonZeroI32
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroI32
[src]
Converts NonZeroU16
to NonZeroI32
losslessly.
impl From<NonZeroU16> for NonZeroI64
1.41.0[src]
impl From<NonZeroU16> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroI64
[src]
Converts NonZeroU16
to NonZeroI64
losslessly.
impl From<NonZeroU16> for NonZeroI128
1.41.0[src]
impl From<NonZeroU16> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroI128
[src]
Converts NonZeroU16
to NonZeroI128
losslessly.
impl From<NonZeroU16> for NonZeroU32
1.41.0[src]
impl From<NonZeroU16> for NonZeroU32
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroU32
[src]
Converts NonZeroU16
to NonZeroU32
losslessly.
impl From<NonZeroU16> for NonZeroU64
1.41.0[src]
impl From<NonZeroU16> for NonZeroU64
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroU64
[src]
Converts NonZeroU16
to NonZeroU64
losslessly.
impl From<NonZeroU16> for NonZeroU128
1.41.0[src]
impl From<NonZeroU16> for NonZeroU128
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroU128
[src]
Converts NonZeroU16
to NonZeroU128
losslessly.
impl From<NonZeroU16> for NonZeroUsize
1.41.0[src]
impl From<NonZeroU16> for NonZeroUsize
1.41.0[src]pub fn from(small: NonZeroU16) -> NonZeroUsize
[src]
Converts NonZeroU16
to NonZeroUsize
losslessly.
impl From<NonZeroU32> for u32
1.31.0[src]
impl From<NonZeroU32> for u32
1.31.0[src]pub fn from(nonzero: NonZeroU32) -> u32
[src]
Converts a NonZeroU32
into an u32
impl From<NonZeroU32> for NonZeroI64
1.41.0[src]
impl From<NonZeroU32> for NonZeroI64
1.41.0[src]pub fn from(small: NonZeroU32) -> NonZeroI64
[src]
Converts NonZeroU32
to NonZeroI64
losslessly.
impl From<NonZeroU32> for NonZeroI128
1.41.0[src]
impl From<NonZeroU32> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroU32) -> NonZeroI128
[src]
Converts NonZeroU32
to NonZeroI128
losslessly.
impl From<NonZeroU32> for NonZeroU64
1.41.0[src]
impl From<NonZeroU32> for NonZeroU64
1.41.0[src]pub fn from(small: NonZeroU32) -> NonZeroU64
[src]
Converts NonZeroU32
to NonZeroU64
losslessly.
impl From<NonZeroU32> for NonZeroU128
1.41.0[src]
impl From<NonZeroU32> for NonZeroU128
1.41.0[src]pub fn from(small: NonZeroU32) -> NonZeroU128
[src]
Converts NonZeroU32
to NonZeroU128
losslessly.
impl From<NonZeroU64> for u64
1.31.0[src]
impl From<NonZeroU64> for u64
1.31.0[src]pub fn from(nonzero: NonZeroU64) -> u64
[src]
Converts a NonZeroU64
into an u64
impl From<NonZeroU64> for NonZeroI128
1.41.0[src]
impl From<NonZeroU64> for NonZeroI128
1.41.0[src]pub fn from(small: NonZeroU64) -> NonZeroI128
[src]
Converts NonZeroU64
to NonZeroI128
losslessly.
impl From<NonZeroU64> for NonZeroU128
1.41.0[src]
impl From<NonZeroU64> for NonZeroU128
1.41.0[src]pub fn from(small: NonZeroU64) -> NonZeroU128
[src]
Converts NonZeroU64
to NonZeroU128
losslessly.
impl From<NonZeroU128> for u128
1.31.0[src]
impl From<NonZeroU128> for u128
1.31.0[src]pub fn from(nonzero: NonZeroU128) -> u128
[src]
Converts a NonZeroU128
into an u128
impl From<NonZeroUsize> for usize
1.31.0[src]
impl From<NonZeroUsize> for usize
1.31.0[src]pub fn from(nonzero: NonZeroUsize) -> usize
[src]
Converts a NonZeroUsize
into an usize
impl From<PathBuf> for Box<Path>
1.20.0[src]
impl From<PathBuf> for Box<Path>
1.20.0[src]fn from(p: PathBuf) -> Box<Path>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a PathBuf
into a Box<Path>
This conversion currently should not allocate memory, but this behavior is not guaranteed on all platforms or in all future versions.
impl From<ChildStderr> for Stdio
1.20.0[src]
impl From<ChildStderr> for Stdio
1.20.0[src]fn from(child: ChildStderr) -> Stdio
[src]
Converts a ChildStderr
into a Stdio
Examples
use std::process::{Command, Stdio}; let reverse = Command::new("rev") .arg("non_existing_file.txt") .stderr(Stdio::piped()) .spawn() .expect("failed reverse command"); let cat = Command::new("cat") .arg("-") .stdin(reverse.stderr.unwrap()) // Converted into a Stdio here .output() .expect("failed echo command"); assert_eq!( String::from_utf8_lossy(&cat.stdout), "rev: cannot open non_existing_file.txt: No such file or directory\n" );Run
impl From<ChildStdin> for Stdio
1.20.0[src]
impl From<ChildStdin> for Stdio
1.20.0[src]fn from(child: ChildStdin) -> Stdio
[src]
Converts a ChildStdin
into a Stdio
Examples
ChildStdin
will be converted to Stdio
using Stdio::from
under the hood.
use std::process::{Command, Stdio}; let reverse = Command::new("rev") .stdin(Stdio::piped()) .spawn() .expect("failed reverse command"); let _echo = Command::new("echo") .arg("Hello, world!") .stdout(reverse.stdin.unwrap()) // Converted into a Stdio here .output() .expect("failed echo command"); // "!dlrow ,olleH" echoed to consoleRun
impl From<ChildStdout> for Stdio
1.20.0[src]
impl From<ChildStdout> for Stdio
1.20.0[src]fn from(child: ChildStdout) -> Stdio
[src]
Converts a ChildStdout
into a Stdio
Examples
ChildStdout
will be converted to Stdio
using Stdio::from
under the hood.
use std::process::{Command, Stdio}; let hello = Command::new("echo") .arg("Hello, world!") .stdout(Stdio::piped()) .spawn() .expect("failed echo command"); let reverse = Command::new("rev") .stdin(hello.stdout.unwrap()) // Converted into a Stdio here .output() .expect("failed reverse command"); assert_eq!(reverse.stdout, b"!dlrow ,olleH\n");Run
impl From<String> for Box<str, Global>
1.20.0[src]
impl From<String> for Box<str, Global>
1.20.0[src]pub fn from(s: String) -> Box<str, Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<String> for Box<dyn Error + Send + Sync>
[src]
impl From<String> for Box<dyn Error + Send + Sync>
[src]fn from(err: String) -> Box<dyn Error + Send + Sync>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a String
into a box of dyn Error
+ Send
+ Sync
.
Examples
use std::error::Error; use std::mem; let a_string_error = "a string error".to_string(); let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_string_error); assert!( mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))Run
impl From<String> for Box<dyn Error>
1.6.0[src]
impl From<String> for Box<dyn Error>
1.6.0[src]fn from(str_err: String) -> Box<dyn Error>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl From<String> for Vec<u8, Global>
1.14.0[src]
impl From<String> for Vec<u8, Global>
1.14.0[src]impl From<RecvError> for RecvTimeoutError
1.24.0[src]
impl From<RecvError> for RecvTimeoutError
1.24.0[src]fn from(err: RecvError) -> RecvTimeoutError
[src]
Converts a RecvError
into a RecvTimeoutError
.
This conversion always returns RecvTimeoutError::Disconnected
.
No data is allocated on the heap.
impl From<RecvError> for TryRecvError
1.24.0[src]
impl From<RecvError> for TryRecvError
1.24.0[src]fn from(err: RecvError) -> TryRecvError
[src]
Converts a RecvError
into a TryRecvError
.
This conversion always returns TryRecvError::Disconnected
.
No data is allocated on the heap.
impl<'_> From<&'_ str> for Box<str, Global>
1.17.0[src]
impl<'_> From<&'_ str> for Box<str, Global>
1.17.0[src]pub fn from(s: &str) -> Box<str, Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'_> From<Cow<'_, str>> for Box<str, Global>
1.45.0[src]
impl<'_> From<Cow<'_, str>> for Box<str, Global>
1.45.0[src]pub fn from(cow: Cow<'_, str>) -> Box<str, Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'_, T> From<Cow<'_, [T]>> for Box<[T], Global> where
T: Copy,
1.45.0[src]
impl<'_, T> From<Cow<'_, [T]>> for Box<[T], Global> where
T: Copy,
1.45.0[src]pub fn from(cow: Cow<'_, [T]>) -> Box<[T], Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'_, T> From<&'_ [T]> for Box<[T], Global> where
T: Copy,
1.17.0[src]
impl<'_, T> From<&'_ [T]> for Box<[T], Global> where
T: Copy,
1.17.0[src]pub fn from(slice: &[T]) -> Box<[T], Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'a> From<&'_ str> for Box<dyn Error + Send + Sync + 'a>
[src]
impl<'a> From<&'_ str> for Box<dyn Error + Send + Sync + 'a>
[src]fn from(err: &str) -> Box<dyn Error + Send + Sync + 'a>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'a> From<Cow<'a, str>> for Box<dyn Error>
1.22.0[src]
impl<'a> From<Cow<'a, str>> for Box<dyn Error>
1.22.0[src]fn from(err: Cow<'a, str>) -> Box<dyn Error>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a>
1.22.0[src]
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a>
1.22.0[src]fn from(err: Cow<'b, str>) -> Box<dyn Error + Send + Sync + 'a>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a Cow
into a box of dyn Error
+ Send
+ Sync
.
Examples
use std::error::Error; use std::mem; use std::borrow::Cow; let a_cow_str_error = Cow::from("a str error"); let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_cow_str_error); assert!( mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))Run
impl<'a, B> From<Cow<'a, B>> for Rc<B> where
B: ToOwned + ?Sized,
Rc<B>: From<&'a B>,
Rc<B>: From<<B as ToOwned>::Owned>,
1.45.0[src]
impl<'a, B> From<Cow<'a, B>> for Rc<B> where
B: ToOwned + ?Sized,
Rc<B>: From<&'a B>,
Rc<B>: From<<B as ToOwned>::Owned>,
1.45.0[src]impl<'a, B> From<Cow<'a, B>> for Arc<B> where
B: ToOwned + ?Sized,
Arc<B>: From<&'a B>,
Arc<B>: From<<B as ToOwned>::Owned>,
1.45.0[src]
impl<'a, B> From<Cow<'a, B>> for Arc<B> where
B: ToOwned + ?Sized,
Arc<B>: From<&'a B>,
Arc<B>: From<<B as ToOwned>::Owned>,
1.45.0[src]impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a>
[src]
impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a>
[src]fn from(err: E) -> Box<dyn Error + 'a>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a type of Error
into a box of dyn Error
.
Examples
use std::error::Error; use std::fmt; use std::mem; #[derive(Debug)] struct AnError; impl fmt::Display for AnError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f , "An error") } } impl Error for AnError {} let an_error = AnError; assert!(0 == mem::size_of_val(&an_error)); let a_boxed_error = Box::<dyn Error>::from(an_error); assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))Run
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a>
[src]
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync + 'a>
[src]fn from(err: E) -> Box<dyn Error + Send + Sync + 'a>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a type of Error
+ Send
+ Sync
into a box of
dyn Error
+ Send
+ Sync
.
Examples
use std::error::Error; use std::fmt; use std::mem; #[derive(Debug)] struct AnError; impl fmt::Display for AnError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f , "An error") } } impl Error for AnError {} unsafe impl Send for AnError {} unsafe impl Sync for AnError {} let an_error = AnError; assert!(0 == mem::size_of_val(&an_error)); let a_boxed_error = Box::<dyn Error + Send + Sync>::from(an_error); assert!( mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))Run
impl<'a, T> From<&'a Option<T>> for Option<&'a T>
1.30.0[src]
impl<'a, T> From<&'a Option<T>> for Option<&'a T>
1.30.0[src]pub fn from(o: &'a Option<T>) -> Option<&'a T>
[src]
Converts from &Option<T>
to Option<&T>
.
Examples
Converts an Option<
String
>
into an Option<
usize
>
, preserving the original.
The map
method takes the self
argument by value, consuming the original,
so this technique uses as_ref
to first take an Option
to a reference
to the value inside the original.
let s: Option<String> = Some(String::from("Hello, Rustaceans!")); let o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len()); println!("Can still print s: {:?}", s); assert_eq!(o, Some(18));Run
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T>
1.30.0[src]
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T>
1.30.0[src]impl<'a, T> From<Cow<'a, [T]>> for Vec<T, Global> where
[T]: ToOwned,
<[T] as ToOwned>::Owned == Vec<T, Global>,
1.14.0[src]
impl<'a, T> From<Cow<'a, [T]>> for Vec<T, Global> where
[T]: ToOwned,
<[T] as ToOwned>::Owned == Vec<T, Global>,
1.14.0[src]pub fn from(s: Cow<'a, [T]>) -> Vec<T, Global>ⓘ
[src]
Convert a clone-on-write slice into a vector.
If s
already owns a Vec<T>
, it will be returned directly.
If s
is borrowing a slice, a new Vec<T>
will be allocated and
filled by cloning s
’s items into it.
Examples
let o: Cow<[i32]> = Cow::Owned(vec![1, 2, 3]); let b: Cow<[i32]> = Cow::Borrowed(&[1, 2, 3]); assert_eq!(Vec::from(o), Vec::from(b));Run
impl<A> From<Box<str, A>> for Box<[u8], A> where
A: Allocator,
1.19.0[src]
impl<A> From<Box<str, A>> for Box<[u8], A> where
A: Allocator,
1.19.0[src]pub fn from(s: Box<str, A>) -> Box<[u8], A>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
Converts a Box<str>
into a Box<[u8]>
This conversion does not allocate on the heap and happens in place.
Examples
// create a Box<str> which will be used to create a Box<[u8]> let boxed: Box<str> = Box::from("hello"); let boxed_str: Box<[u8]> = Box::from(boxed); // create a &[u8] which will be used to create a Box<[u8]> let slice: &[u8] = &[104, 101, 108, 108, 111]; let boxed_slice = Box::from(slice); assert_eq!(boxed_slice, boxed_str);Run
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr
1.17.0[src]
impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr
1.17.0[src]fn from(pieces: (I, u16)) -> SocketAddr
[src]
Converts a tuple struct (Into<IpAddr
>, u16
) into a SocketAddr
.
This conversion creates a SocketAddr::V4
for a IpAddr::V4
and creates a SocketAddr::V6
for a IpAddr::V6
.
u16
is treated as port of the newly created SocketAddr
.
impl<T> From<!> for T
1.34.0[src]
impl<T> From<!> for T
1.34.0[src]Stability note: This impl does not yet exist, but we are “reserving space” to add it in the future. See rust-lang/rust#64715 for details.
impl<T> From<BinaryHeap<T>> for Vec<T, Global>
1.5.0[src]
impl<T> From<BinaryHeap<T>> for Vec<T, Global>
1.5.0[src]impl<T> From<VecDeque<T>> for Vec<T, Global>
1.10.0[src]
impl<T> From<VecDeque<T>> for Vec<T, Global>
1.10.0[src]pub fn from(other: VecDeque<T>) -> Vec<T, Global>ⓘ
[src]
Turn a VecDeque<T>
into a Vec<T>
.
This never needs to re-allocate, but does need to do O(n) data movement if the circular buffer doesn’t happen to be at the beginning of the allocation.
Examples
use std::collections::VecDeque; // This one is *O*(1). let deque: VecDeque<_> = (1..5).collect(); let ptr = deque.as_slices().0.as_ptr(); let vec = Vec::from(deque); assert_eq!(vec, [1, 2, 3, 4]); assert_eq!(vec.as_ptr(), ptr); // This one needs data rearranging. let mut deque: VecDeque<_> = (1..5).collect(); deque.push_front(9); deque.push_front(8); let ptr = deque.as_slices().1.as_ptr(); let vec = Vec::from(deque); assert_eq!(vec, [8, 9, 1, 2, 3, 4]); assert_eq!(vec.as_ptr(), ptr);Run
impl<T> From<SendError<T>> for TrySendError<T>
1.24.0[src]
impl<T> From<SendError<T>> for TrySendError<T>
1.24.0[src]fn from(err: SendError<T>) -> TrySendError<T>
[src]
Converts a SendError<T>
into a TrySendError<T>
.
This conversion always returns a TrySendError::Disconnected
containing the data in the SendError<T>
.
No data is allocated on the heap.
impl<T> From<PoisonError<T>> for TryLockError<T>
[src]
impl<T> From<PoisonError<T>> for TryLockError<T>
[src]fn from(err: PoisonError<T>) -> TryLockError<T>
[src]
impl<T> From<Vec<T, Global>> for BinaryHeap<T> where
T: Ord,
1.5.0[src]
impl<T> From<Vec<T, Global>> for BinaryHeap<T> where
T: Ord,
1.5.0[src]pub fn from(vec: Vec<T, Global>) -> BinaryHeap<T>
[src]
Converts a Vec<T>
into a BinaryHeap<T>
.
This conversion happens in-place, and has O(n) time complexity.
impl<T> From<T> for Box<T, Global>
1.6.0[src]
impl<T> From<T> for Box<T, Global>
1.6.0[src]pub fn from(t: T) -> Box<T, Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<T> From<T> for UnsafeCell<T>
1.12.0[src]
impl<T> From<T> for UnsafeCell<T>
1.12.0[src]pub fn from(t: T) -> UnsafeCell<T>
[src]
impl<T> From<T> for SyncOnceCell<T>
[src]
impl<T> From<T> for SyncOnceCell<T>
[src]impl<T> From<T> for Mutex<T>
1.24.0[src]
impl<T> From<T> for Mutex<T>
1.24.0[src]fn from(t: T) -> Self
[src]
Creates a new mutex in an unlocked state ready for use.
This is equivalent to Mutex::new
.
impl<T> From<T> for RwLock<T>
1.24.0[src]
impl<T> From<T> for RwLock<T>
1.24.0[src]fn from(t: T) -> Self
[src]
Creates a new instance of an RwLock<T>
which is unlocked.
This is equivalent to RwLock::new
.
impl<T, A> From<Box<[T], A>> for Vec<T, A> where
A: Allocator,
1.18.0[src]
impl<T, A> From<Box<[T], A>> for Vec<T, A> where
A: Allocator,
1.18.0[src]impl<T, A> From<Box<T, A>> for Pin<Box<T, A>> where
T: ?Sized,
A: Allocator + 'static,
1.33.0[src]
impl<T, A> From<Box<T, A>> for Pin<Box<T, A>> where
T: ?Sized,
A: Allocator + 'static,
1.33.0[src]impl<T, A> From<Vec<T, A>> for Box<[T], A> where
A: Allocator,
1.20.0[src]
impl<T, A> From<Vec<T, A>> for Box<[T], A> where
A: Allocator,
1.20.0[src]pub fn from(v: Vec<T, A>) -> Box<[T], A>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<T, const N: usize> From<[T; N]> for Box<[T], Global>
1.45.0[src]
impl<T, const N: usize> From<[T; N]> for Box<[T], Global>
1.45.0[src]pub fn from(array: [T; N]) -> Box<[T], Global>ⓘNotable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
[src]
Notable traits for Box<I, A>
impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<R: Read + ?Sized> Read for Box<R>impl<W: Write + ?Sized> Write for Box<W>
impl<W> From<IntoInnerError<W>> for Error
[src]
impl<W> From<IntoInnerError<W>> for Error
[src]