pub trait From<T> {
fn from(T) -> Self;
}
Expand description
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);
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)
}
Required methods
Implementations on Foreign Types
sourceimpl From<OwnedFd> for UnixListener
impl From<OwnedFd> for UnixListener
pub fn from(fd: OwnedFd) -> UnixListener
1.20.0 · sourceimpl From<ChildStderr> for Stdio
impl From<ChildStderr> for Stdio
sourcepub fn from(child: ChildStderr) -> Stdio
pub fn from(child: ChildStderr) -> Stdio
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"
);
sourceimpl From<UnixStream> for OwnedFd
impl From<UnixStream> for OwnedFd
pub fn from(unix_stream: UnixStream) -> OwnedFd
sourceimpl<W> From<IntoInnerError<W>> for Error
impl<W> From<IntoInnerError<W>> for Error
pub fn from(iie: IntoInnerError<W>) -> Error
1.17.0 · sourceimpl From<[u8; 16]> for IpAddr
impl From<[u8; 16]> for IpAddr
sourcepub fn from(octets: [u8; 16]) -> IpAddr
pub fn from(octets: [u8; 16]) -> IpAddr
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
);
sourceimpl From<OwnedFd> for TcpListener
impl From<OwnedFd> for TcpListener
pub fn from(owned_fd: OwnedFd) -> TcpListener
1.17.0 · sourceimpl From<[u16; 8]> for IpAddr
impl From<[u16; 8]> for IpAddr
sourcepub fn from(segments: [u16; 8]) -> IpAddr
pub fn from(segments: [u16; 8]) -> IpAddr
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
);
1.16.0 · sourceimpl From<[u16; 8]> for Ipv6Addr
impl From<[u16; 8]> for Ipv6Addr
sourcepub fn from(segments: [u16; 8]) -> Ipv6Addr
pub fn from(segments: [u16; 8]) -> Ipv6Addr
Creates an Ipv6Addr
from an eight element 16-bit array.
Examples
use std::net::Ipv6Addr;
let addr = Ipv6Addr::from([
525u16, 524u16, 523u16, 522u16,
521u16, 520u16, 519u16, 518u16,
]);
assert_eq!(
Ipv6Addr::new(
0x20d, 0x20c,
0x20b, 0x20a,
0x209, 0x208,
0x207, 0x206
),
addr
);
1.17.0 · sourceimpl<I> From<(I, u16)> for SocketAddr where
I: Into<IpAddr>,
impl<I> From<(I, u16)> for SocketAddr where
I: Into<IpAddr>,
sourcepub fn from(pieces: (I, u16)) -> SocketAddr
pub fn from(pieces: (I, u16)) -> SocketAddr
Converts a tuple struct (Into<IpAddr
>, u16
) into a SocketAddr
.
This conversion creates a SocketAddr::V4
for an IpAddr::V4
and creates a SocketAddr::V6
for an IpAddr::V6
.
u16
is treated as port of the newly created SocketAddr
.
sourceimpl<T> From<T> for SyncOnceCell<T>
impl<T> From<T> for SyncOnceCell<T>
sourcepub fn from(value: T) -> SyncOnceCell<T>
pub fn from(value: T) -> SyncOnceCell<T>
Create a new cell with its contents set to value
.
Example
#![feature(once_cell)]
use std::lazy::SyncOnceCell;
let a = SyncOnceCell::from(3);
let b = SyncOnceCell::new();
b.set(3)?;
assert_eq!(a, b);
Ok(())
sourceimpl From<OwnedFd> for UnixStream
impl From<OwnedFd> for UnixStream
pub fn from(owned: OwnedFd) -> UnixStream
sourceimpl From<TcpListener> for OwnedFd
impl From<TcpListener> for OwnedFd
pub fn from(tcp_listener: TcpListener) -> OwnedFd
sourceimpl From<UnixDatagram> for OwnedFd
impl From<UnixDatagram> for OwnedFd
pub fn from(unix_datagram: UnixDatagram) -> OwnedFd
1.20.0 · sourceimpl From<ChildStdin> for Stdio
impl From<ChildStdin> for Stdio
sourcepub fn from(child: ChildStdin) -> Stdio
pub fn from(child: ChildStdin) -> Stdio
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 console
sourceimpl From<OwnedFd> for UnixDatagram
impl From<OwnedFd> for UnixDatagram
pub fn from(owned: OwnedFd) -> UnixDatagram
1.16.0 · sourceimpl From<SocketAddrV6> for SocketAddr
impl From<SocketAddrV6> for SocketAddr
sourcepub fn from(sock6: SocketAddrV6) -> SocketAddr
pub fn from(sock6: SocketAddrV6) -> SocketAddr
Converts a SocketAddrV6
into a SocketAddr::V6
.
1.56.0 · sourceimpl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState> where
K: Eq + Hash,
impl<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState> where
K: Eq + Hash,
1.16.0 · sourceimpl From<SocketAddrV4> for SocketAddr
impl From<SocketAddrV4> for SocketAddr
sourcepub fn from(sock4: SocketAddrV4) -> SocketAddr
pub fn from(sock4: SocketAddrV4) -> SocketAddr
Converts a SocketAddrV4
into a SocketAddr::V4
.
1.20.0 · sourceimpl From<File> for Stdio
impl From<File> for Stdio
sourcepub fn from(file: File) -> Stdio
pub fn from(file: File) -> 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");
sourceimpl From<ChildStdin> for OwnedFd
impl From<ChildStdin> for OwnedFd
pub fn from(child_stdin: ChildStdin) -> OwnedFd
sourceimpl From<ChildStdout> for OwnedFd
impl From<ChildStdout> for OwnedFd
pub fn from(child_stdout: ChildStdout) -> OwnedFd
1.14.0 · sourceimpl From<ErrorKind> for Error
impl From<ErrorKind> for Error
Intended for use for errors not exposed to the user, where allocating onto the heap (for normal construction via Error::new) is too costly.
1.20.0 · sourceimpl From<ChildStdout> for Stdio
impl From<ChildStdout> for Stdio
sourcepub fn from(child: ChildStdout) -> Stdio
pub fn from(child: ChildStdout) -> Stdio
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");
1.9.0 · sourceimpl From<[u8; 16]> for Ipv6Addr
impl From<[u8; 16]> for Ipv6Addr
sourcepub fn from(octets: [u8; 16]) -> Ipv6Addr
pub fn from(octets: [u8; 16]) -> Ipv6Addr
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
);
sourceimpl From<ChildStderr> for OwnedFd
impl From<ChildStderr> for OwnedFd
pub fn from(child_stderr: ChildStderr) -> OwnedFd
sourceimpl From<UnixListener> for OwnedFd
impl From<UnixListener> for OwnedFd
pub fn from(listener: UnixListener) -> OwnedFd
sourceimpl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i64, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i64, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroUsize> for usize
impl From<NonZeroUsize> for usize
const: unstable · sourcepub fn from(nonzero: NonZeroUsize) -> usize
pub fn from(nonzero: NonZeroUsize) -> usize
Converts a NonZeroUsize
into an usize
1.36.0 (const: unstable) · sourceimpl From<Infallible> for TryFromSliceError
impl From<Infallible> for TryFromSliceError
pub fn from(x: Infallible) -> TryFromSliceError
sourceimpl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroU64> for u64
impl From<NonZeroU64> for u64
const: unstable · sourcepub fn from(nonzero: NonZeroU64) -> u64
pub fn from(nonzero: NonZeroU64) -> u64
Converts a NonZeroU64
into an u64
sourceimpl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<T, const LANES: usize> From<[T; LANES]> for Simd<T, LANES> where
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> From<[T; LANES]> for Simd<T, LANES> where
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<T, const LANES: usize> From<Simd<T, LANES>> for [T; LANES] where
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> From<Simd<T, LANES>> for [T; LANES] where
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
1.30.0 (const: unstable) · sourceimpl<'a, T> From<&'a Option<T>> for Option<&'a T>
impl<'a, T> From<&'a Option<T>> for Option<&'a T>
const: unstable · sourcepub fn from(o: &'a Option<T>) -> Option<&'a T>
pub fn from(o: &'a Option<T>) -> Option<&'a T>
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 from
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));
1.31.0 (const: unstable) · sourceimpl From<NonZeroU32> for u32
impl From<NonZeroU32> for u32
const: unstable · sourcepub fn from(nonzero: NonZeroU32) -> u32
pub fn from(nonzero: NonZeroU32) -> u32
Converts a NonZeroU32
into an u32
sourceimpl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.13.0 (const: unstable) · sourceimpl From<u8> for char
impl From<u8> for char
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.
sourceimpl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i16, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<isize, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroI16> for i16
impl From<NonZeroI16> for i16
const: unstable · sourcepub fn from(nonzero: NonZeroI16) -> i16
pub fn from(nonzero: NonZeroI16) -> i16
Converts a NonZeroI16
into an i16
sourceimpl<T, const LANES: usize> From<Mask<T, LANES>> for Simd<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> From<Mask<T, LANES>> for Simd<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroI32> for i32
impl From<NonZeroI32> for i32
const: unstable · sourcepub fn from(nonzero: NonZeroI32) -> i32
pub fn from(nonzero: NonZeroI32) -> i32
Converts a NonZeroI32
into an i32
sourceimpl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<T, const LANES: usize> From<[bool; LANES]> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> From<[bool; LANES]> for Mask<T, LANES> where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroU16> for u16
impl From<NonZeroU16> for u16
const: unstable · sourcepub fn from(nonzero: NonZeroU16) -> u16
pub fn from(nonzero: NonZeroU16) -> u16
Converts a NonZeroU16
into an u16
sourceimpl<const LANES: usize> From<Mask<i8, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i8, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroI128> for i128
impl From<NonZeroI128> for i128
const: unstable · sourcepub fn from(nonzero: NonZeroI128) -> i128
pub fn from(nonzero: NonZeroI128) -> i128
Converts a NonZeroI128
into an i128
sourceimpl<T, const LANES: usize> From<Mask<T, LANES>> for [bool; LANES] where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
impl<T, const LANES: usize> From<Mask<T, LANES>> for [bool; LANES] where
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i32, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i32, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroI64> for i64
impl From<NonZeroI64> for i64
const: unstable · sourcepub fn from(nonzero: NonZeroI64) -> i64
pub fn from(nonzero: NonZeroI64) -> i64
Converts a NonZeroI64
into an i64
sourceimpl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i32, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroU128> for u128
impl From<NonZeroU128> for u128
const: unstable · sourcepub fn from(nonzero: NonZeroU128) -> u128
pub fn from(nonzero: NonZeroU128) -> u128
Converts a NonZeroU128
into an u128
sourceimpl<const LANES: usize> From<Mask<i16, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i16, LANES>> for Mask<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.30.0 (const: unstable) · sourceimpl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T>
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T>
const: unstable · sourcepub fn from(o: &'a mut Option<T>) -> Option<&'a mut T>
pub fn from(o: &'a mut Option<T>) -> Option<&'a mut T>
Converts from &mut Option<T>
to Option<&mut T>
Examples
let mut s = Some(String::from("Hello"));
let o: Option<&mut String> = Option::from(&mut s);
match o {
Some(t) => *t = String::from("Hello, Rustaceans!"),
None => (),
}
assert_eq!(s, Some(String::from("Hello, Rustaceans!")));
sourceimpl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i64, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i8, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroIsize> for isize
impl From<NonZeroIsize> for isize
const: unstable · sourcepub fn from(nonzero: NonZeroIsize) -> isize
pub fn from(nonzero: NonZeroIsize) -> isize
Converts a NonZeroIsize
into an isize
sourceimpl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i8, LANES>> for Mask<i64, LANES> where
LaneCount<LANES>: SupportedLaneCount,
sourceimpl From<LayoutError> for TryReserveErrorKind
impl From<LayoutError> for TryReserveErrorKind
sourcepub fn from(LayoutError) -> TryReserveErrorKind
pub fn from(LayoutError) -> TryReserveErrorKind
Always evaluates to TryReserveErrorKind::CapacityOverflow
.
sourceimpl From<TryReserveErrorKind> for TryReserveError
impl From<TryReserveErrorKind> for TryReserveError
pub fn from(kind: TryReserveErrorKind) -> TryReserveError
1.56.0 · sourceimpl<T, const N: usize> From<[T; N]> for LinkedList<T>
impl<T, const N: usize> From<[T; N]> for LinkedList<T>
sourcepub fn from(arr: [T; N]) -> LinkedList<T>
pub fn from(arr: [T; N]) -> LinkedList<T>
Converts a [T; N]
into a LinkedList<T>
.
use std::collections::LinkedList;
let list1 = LinkedList::from([1, 2, 3, 4]);
let list2: LinkedList<_> = [1, 2, 3, 4].into();
assert_eq!(list1, list2);
1.33.0 (const: unstable) · sourceimpl<T, A> From<Box<T, A>> for Pin<Box<T, A>> where
A: Allocator + 'static,
T: ?Sized,
impl<T, A> From<Box<T, A>> for Pin<Box<T, A>> where
A: Allocator + 'static,
T: ?Sized,
1.5.0 · sourceimpl<T> From<Vec<T, Global>> for BinaryHeap<T> where
T: Ord,
impl<T> From<Vec<T, Global>> for BinaryHeap<T> where
T: Ord,
sourcepub fn from(vec: Vec<T, Global>) -> BinaryHeap<T>
pub fn from(vec: Vec<T, Global>) -> BinaryHeap<T>
Converts a Vec<T>
into a BinaryHeap<T>
.
This conversion happens in-place, and has O(n) time complexity.
1.18.0 · sourceimpl From<Box<str, Global>> for String
impl From<Box<str, Global>> for String
1.14.0 · sourceimpl<'a> From<Cow<'a, str>> for String
impl<'a> From<Cow<'a, str>> for String
sourcepub fn from(s: Cow<'a, str>) -> String
pub fn from(s: Cow<'a, str>) -> String
Converts a clone-on-write string to an owned
instance of String
.
This extracts the owned string, clones the string if it is not already owned.
Example
// If the string is not owned...
let cow: Cow<str> = Cow::Borrowed("eggplant");
// It will allocate on the heap and copy the string.
let owned: String = String::from(cow);
assert_eq!(&owned[..], "eggplant");
1.56.0 · sourceimpl<T, const N: usize> From<[T; N]> for BinaryHeap<T> where
T: Ord,
impl<T, const N: usize> From<[T; N]> for BinaryHeap<T> where
T: Ord,
sourcepub fn from(arr: [T; N]) -> BinaryHeap<T>
pub fn from(arr: [T; N]) -> BinaryHeap<T>
use std::collections::BinaryHeap;
let mut h1 = BinaryHeap::from([1, 4, 2, 3]);
let mut h2: BinaryHeap<_> = [1, 4, 2, 3].into();
while let Some((a, b)) = h1.pop().zip(h2.pop()) {
assert_eq!(a, b);
}
Implementors
impl From<Infallible> for TryFromIntError
impl From<bool> for AtomicBool
impl From<i8> for AtomicI8
impl From<i16> for AtomicI16
impl From<i32> for AtomicI32
impl From<i64> for AtomicI64
impl From<isize> for AtomicIsize
impl From<!> for Infallible
impl From<!> for TryFromIntError
impl From<u8> for AtomicU8
impl From<u16> for AtomicU16
impl From<u32> for AtomicU32
impl From<u64> for AtomicU64
impl From<usize> for AtomicUsize
impl From<NonZeroI8> for NonZeroI16
impl From<NonZeroI8> for NonZeroI32
impl From<NonZeroI8> for NonZeroI64
impl From<NonZeroI8> for NonZeroI128
impl From<NonZeroI8> for NonZeroIsize
impl From<NonZeroI16> for NonZeroI32
impl From<NonZeroI16> for NonZeroI64
impl From<NonZeroI16> for NonZeroI128
impl From<NonZeroI16> for NonZeroIsize
impl From<NonZeroI32> for NonZeroI64
impl From<NonZeroI32> for NonZeroI128
impl From<NonZeroI64> for NonZeroI128
impl From<NonZeroU8> for NonZeroI16
impl From<NonZeroU8> for NonZeroI32
impl From<NonZeroU8> for NonZeroI64
impl From<NonZeroU8> for NonZeroI128
impl From<NonZeroU8> for NonZeroIsize
impl From<NonZeroU8> for NonZeroU16
impl From<NonZeroU8> for NonZeroU32
impl From<NonZeroU8> for NonZeroU64
impl From<NonZeroU8> for NonZeroU128
impl From<NonZeroU8> for NonZeroUsize
impl From<NonZeroU16> for NonZeroI32
impl From<NonZeroU16> for NonZeroI64
impl From<NonZeroU16> for NonZeroI128
impl From<NonZeroU16> for NonZeroU32
impl From<NonZeroU16> for NonZeroU64
impl From<NonZeroU16> for NonZeroU128
impl From<NonZeroU16> for NonZeroUsize
impl From<NonZeroU32> for NonZeroI64
impl From<NonZeroU32> for NonZeroI128
impl From<NonZeroU32> for NonZeroU64
impl From<NonZeroU32> for NonZeroU128
impl From<NonZeroU64> for NonZeroI128
impl From<NonZeroU64> for NonZeroU128
impl From<RecvError> for RecvTimeoutError
impl From<RecvError> for TryRecvError
impl From<String> for Box<str, Global>
impl From<String> for Box<dyn Error + 'static, Global>
impl From<String> for Box<dyn Error + Send + Sync + 'static, Global>
impl From<String> for Rc<str>
impl From<String> for Arc<str>
impl From<String> for Vec<u8, Global>
impl From<StreamResult> for Result<MZStatus, MZError>
impl From<CString> for Box<CStr, Global>
impl From<CString> for Rc<CStr>
impl From<CString> for Arc<CStr>
impl From<CString> for Vec<u8, Global>
impl From<OsString> for Box<OsStr, Global>
impl From<OsString> for Rc<OsStr>
impl From<OsString> for Arc<OsStr>
impl From<PathBuf> for Box<Path, Global>
impl From<PathBuf> for Rc<Path>
impl From<PathBuf> for Arc<Path>
impl<'_> From<&'_ str> for Box<str, Global>
impl<'_> From<&'_ str> for Box<dyn Error + 'static, Global>
impl<'_> From<&'_ str> for Rc<str>
impl<'_> From<&'_ str> for Arc<str>
impl<'_> From<&'_ str> for Vec<u8, Global>
impl<'_> From<&'_ StreamResult> for Result<MZStatus, MZError>
impl<'_> From<&'_ CStr> for Box<CStr, Global>
impl<'_> From<&'_ CStr> for Rc<CStr>
impl<'_> From<&'_ CStr> for Arc<CStr>
impl<'_> From<&'_ OsStr> for Box<OsStr, Global>
impl<'_> From<&'_ OsStr> for Rc<OsStr>
impl<'_> From<&'_ OsStr> for Arc<OsStr>
impl<'_> From<&'_ Path> for Box<Path, Global>
impl<'_> From<&'_ Path> for Rc<Path>
impl<'_> From<&'_ Path> for Arc<Path>
impl<'_> From<Cow<'_, str>> for Box<str, Global>
impl<'_> From<Cow<'_, CStr>> for Box<CStr, Global>
impl<'_> From<Cow<'_, OsStr>> for Box<OsStr, Global>
impl<'_> From<Cow<'_, Path>> for Box<Path, Global>
impl<'_, T> From<Cow<'_, [T]>> for Box<[T], Global> where
T: Copy,
impl<'_, T> From<&'_ T> for NonNull<T> where
T: ?Sized,
impl<'_, T> From<&'_ mut T> for NonNull<T> where
T: ?Sized,
impl<'_, T> From<&'_ [T]> for Box<[T], Global> where
T: Copy,
impl<'_, T> From<&'_ [T]> for Rc<[T]> where
T: Clone,
impl<'_, T> From<&'_ [T]> for Arc<[T]> where
T: Clone,
impl<'_, T> From<&'_ [T]> for Vec<T, Global> where
T: Clone,
impl<'_, T> From<&'_ mut [T]> for Vec<T, Global> where
T: Clone,
impl<'a> From<&'a str> for Cow<'a, str>
impl<'a> From<&'a String> for Cow<'a, str>
impl<'a> From<&'a CStr> for Cow<'a, CStr>
impl<'a> From<&'a CString> for Cow<'a, CStr>
impl<'a> From<&'a OsStr> for Cow<'a, OsStr>
impl<'a> From<&'a OsString> for Cow<'a, OsStr>
impl<'a> From<&'a Path> for Cow<'a, Path>
impl<'a> From<&'a PathBuf> for Cow<'a, Path>
impl<'a> From<Cow<'a, str>> for Box<dyn Error + 'static, Global>
impl<'a> From<String> for Cow<'a, str>
impl<'a> From<CString> for Cow<'a, CStr>
impl<'a> From<OsString> for Cow<'a, OsStr>
impl<'a> From<PathBuf> for Cow<'a, Path>
impl<'a, '_> From<&'_ str> for Box<dyn Error + Send + Sync + 'a, Global>
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a, Global>
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>,
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>,
impl<'a, E> From<E> for Box<dyn Error + 'a, Global> where
E: 'a + Error,
impl<'a, E> From<E> for Box<dyn Error + Send + Sync + 'a, Global> where
E: 'a + Error + Send + Sync,
impl<'a, T> From<&'a Vec<T, Global>> for Cow<'a, [T]> where
T: Clone,
impl<'a, T> From<Cow<'a, [T]>> for Vec<T, Global> where
[T]: ToOwned,
<[T] as ToOwned>::Owned == Vec<T, Global>,
impl<'a, T> From<&'a [T]> for Cow<'a, [T]> where
T: Clone,
impl<'a, T> From<Vec<T, Global>> for Cow<'a, [T]> where
T: Clone,
impl<A> From<Box<str, A>> for Box<[u8], A> where
A: Allocator,
impl<K, V, const N: usize> From<[(K, V); N]> for BTreeMap<K, V> where
K: Ord,
impl<T> From<!> for T
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.