Trait concordium_std::convert::From
1.0.0 · source · [−]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. The From
trait is intended for perfect conversions.
If the conversion can fail or is not perfect, 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
1.20.0 · sourceimpl From<ChildStdin> for Stdio
impl From<ChildStdin> for Stdio
sourcefn from(child: ChildStdin) -> Stdio
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
1.24.0 · sourceimpl From<RecvError> for TryRecvError
impl From<RecvError> for TryRecvError
sourcefn from(err: RecvError) -> TryRecvError
fn from(err: RecvError) -> TryRecvError
Converts a RecvError
into a TryRecvError
.
This conversion always returns TryRecvError::Disconnected
.
No data is allocated on the heap.
1.16.0 · sourceimpl From<SocketAddrV6> for SocketAddr
impl From<SocketAddrV6> for SocketAddr
sourcefn from(sock6: SocketAddrV6) -> SocketAddr
fn from(sock6: SocketAddrV6) -> SocketAddr
Converts a SocketAddrV6
into a SocketAddr::V6
.
1.20.0 · sourceimpl From<ChildStderr> for Stdio
impl From<ChildStderr> for Stdio
sourcefn from(child: ChildStderr) -> Stdio
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"
);
1.16.0 · sourceimpl From<SocketAddrV4> for SocketAddr
impl From<SocketAddrV4> for SocketAddr
sourcefn from(sock4: SocketAddrV4) -> SocketAddr
fn from(sock4: SocketAddrV4) -> SocketAddr
Converts a SocketAddrV4
into a SocketAddr::V4
.
sourceimpl<T> From<T> for SyncOnceCell<T>
impl<T> From<T> for SyncOnceCell<T>
sourcefn from(value: T) -> SyncOnceCell<T>
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(())
1.17.0 · sourceimpl From<[u8; 16]> for IpAddr
impl From<[u8; 16]> for IpAddr
sourcefn from(octets: [u8; 16]) -> IpAddr
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
);
1.20.0 · sourceimpl From<File> for Stdio
impl From<File> for Stdio
sourcefn from(file: File) -> Stdio
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<W> From<IntoInnerError<W>> for Error
impl<W> From<IntoInnerError<W>> for Error
fn from(iie: IntoInnerError<W>) -> Error
sourceimpl<T> From<PoisonError<T>> for TryLockError<T>
impl<T> From<PoisonError<T>> for TryLockError<T>
fn from(err: PoisonError<T>) -> TryLockError<T>
1.24.0 · sourceimpl<T> From<T> for Mutex<T>
impl<T> From<T> for Mutex<T>
sourcefn from(t: T) -> Mutex<T>
fn from(t: T) -> Mutex<T>
Creates a new mutex in an unlocked state ready for use.
This is equivalent to Mutex::new
.
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.24.0 · sourceimpl From<RecvError> for RecvTimeoutError
impl From<RecvError> for RecvTimeoutError
sourcefn from(err: RecvError) -> RecvTimeoutError
fn from(err: RecvError) -> RecvTimeoutError
Converts a RecvError
into a RecvTimeoutError
.
This conversion always returns RecvTimeoutError::Disconnected
.
No data is allocated on the heap.
1.24.0 · sourceimpl<T> From<T> for RwLock<T>
impl<T> From<T> for RwLock<T>
sourcefn from(t: T) -> RwLock<T>
fn from(t: T) -> RwLock<T>
Creates a new instance of an RwLock<T>
which is unlocked.
This is equivalent to RwLock::new
.
1.20.0 · sourceimpl From<ChildStdout> for Stdio
impl From<ChildStdout> for Stdio
sourcefn from(child: ChildStdout) -> Stdio
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.24.0 · sourceimpl<T> From<SendError<T>> for TrySendError<T>
impl<T> From<SendError<T>> for TrySendError<T>
sourcefn from(err: SendError<T>) -> TrySendError<T>
fn from(err: SendError<T>) -> TrySendError<T>
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.
1.16.0 · sourceimpl From<[u16; 8]> for Ipv6Addr
impl From<[u16; 8]> for Ipv6Addr
sourcefn from(segments: [u16; 8]) -> Ipv6Addr
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>,
sourcefn from(pieces: (I, u16)) -> SocketAddr
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
.
1.17.0 · sourceimpl From<[u16; 8]> for IpAddr
impl From<[u16; 8]> for IpAddr
sourcefn from(segments: [u16; 8]) -> IpAddr
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.9.0 · sourceimpl From<[u8; 16]> for Ipv6Addr
impl From<[u8; 16]> for Ipv6Addr
sourcefn from(octets: [u8; 16]) -> Ipv6Addr
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<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<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<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i32, LANES>> for Mask<i16, LANES> where
LaneCount<LANES>: SupportedLaneCount,
1.31.0 (const: unstable) · sourceimpl From<NonZeroI32> for i32
impl From<NonZeroI32> for i32
const: unstable · sourcefn from(nonzero: NonZeroI32) -> i32
fn from(nonzero: NonZeroI32) -> i32
Converts a NonZeroI32
into an i32
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<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,
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<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,
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,
1.23.0 (const: unstable) · sourceimpl From<isize> for AtomicIsize
impl From<isize> for AtomicIsize
const: unstable · sourcefn from(v: isize) -> AtomicIsize
fn from(v: isize) -> AtomicIsize
Converts an isize
into an AtomicIsize
.
1.31.0 (const: unstable) · sourceimpl From<NonZeroU128> for u128
impl From<NonZeroU128> for u128
const: unstable · sourcefn from(nonzero: NonZeroU128) -> u128
fn from(nonzero: NonZeroU128) -> u128
Converts a NonZeroU128
into an u128
1.31.0 (const: unstable) · sourceimpl From<NonZeroI64> for i64
impl From<NonZeroI64> for i64
const: unstable · sourcefn from(nonzero: NonZeroI64) -> i64
fn from(nonzero: NonZeroI64) -> i64
Converts a NonZeroI64
into an i64
1.23.0 (const: unstable) · sourceimpl From<usize> for AtomicUsize
impl From<usize> for AtomicUsize
const: unstable · sourcefn from(v: usize) -> AtomicUsize
fn from(v: usize) -> AtomicUsize
Converts an usize
into an AtomicUsize
.
1.31.0 (const: unstable) · sourceimpl From<NonZeroI128> for i128
impl From<NonZeroI128> for i128
const: unstable · sourcefn from(nonzero: NonZeroI128) -> i128
fn from(nonzero: NonZeroI128) -> i128
Converts a NonZeroI128
into an i128
1.36.0 (const: unstable) · sourceimpl From<Infallible> for TryFromSliceError
impl From<Infallible> for TryFromSliceError
fn from(x: Infallible) -> TryFromSliceError
1.31.0 (const: unstable) · sourceimpl From<NonZeroI16> for i16
impl From<NonZeroI16> for i16
const: unstable · sourcefn from(nonzero: NonZeroI16) -> i16
fn from(nonzero: NonZeroI16) -> i16
Converts a NonZeroI16
into an i16
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<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,
1.31.0 (const: unstable) · sourceimpl From<NonZeroUsize> for usize
impl From<NonZeroUsize> for usize
const: unstable · sourcefn from(nonzero: NonZeroUsize) -> usize
fn from(nonzero: NonZeroUsize) -> usize
Converts a NonZeroUsize
into an usize
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.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<isize, LANES> where
LaneCount<LANES>: SupportedLaneCount,
impl<const LANES: usize> From<Mask<i16, LANES>> for Mask<isize, 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,
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,
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,
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,
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<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,
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,
1.31.0 (const: unstable) · sourceimpl From<NonZeroIsize> for isize
impl From<NonZeroIsize> for isize
const: unstable · sourcefn from(nonzero: NonZeroIsize) -> isize
fn from(nonzero: NonZeroIsize) -> isize
Converts a NonZeroIsize
into an isize
1.31.0 (const: unstable) · sourceimpl From<NonZeroU32> for u32
impl From<NonZeroU32> for u32
const: unstable · sourcefn from(nonzero: NonZeroU32) -> u32
fn from(nonzero: NonZeroU32) -> u32
Converts a NonZeroU32
into an u32
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,
1.31.0 (const: unstable) · sourceimpl From<NonZeroU64> for u64
impl From<NonZeroU64> for u64
const: unstable · sourcefn from(nonzero: NonZeroU64) -> u64
fn from(nonzero: NonZeroU64) -> u64
Converts a NonZeroU64
into an u64
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.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 · sourcefn from(o: &'a Option<T>) -> Option<&'a T>
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));
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,
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,
1.31.0 (const: unstable) · sourceimpl From<NonZeroU16> for u16
impl From<NonZeroU16> for u16
const: unstable · sourcefn from(nonzero: NonZeroU16) -> u16
fn from(nonzero: NonZeroU16) -> u16
Converts a NonZeroU16
into an u16
1.24.0 (const: unstable) · sourceimpl From<bool> for AtomicBool
impl From<bool> for AtomicBool
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.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 · sourcefn from(o: &'a mut Option<T>) -> Option<&'a mut T>
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!")));
1.45.0 · sourceimpl<'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, 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.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,
sourceimpl<'a> From<EntrypointName<'a>> for &'a str
impl<'a> From<EntrypointName<'a>> for &'a str
fn from(en: EntrypointName<'a>) -> &'a str
Implementors
impl From<TryReserveErrorKind> for TryReserveError
impl From<LogError> for Reject
Full is mapped to i32::MIN + 3, Malformed is mapped to i32::MIN + 4.
impl From<NewContractNameError> for Reject
MissingInitPrefix is mapped to i32::MIN + 5, TooLong to i32::MIN + 6, ContainsDot to i32::MIN + 9, and InvalidCharacters to i32::MIN + 10.
impl From<NewReceiveNameError> for Reject
MissingDotSeparator is mapped to i32::MIN + 7, TooLong to i32::MIN + 8, and InvalidCharacters to i32::MIN + 11.
impl From<TransferError> for Reject
AmountTooLarge is i32::MIN + 13, MissingAccount is i32::MIN + 14.
impl From<TestStateError> for ParseError
impl From<Infallible> for TryFromIntError
impl From<char> for String
impl From<!> for Infallible
impl From<!> for TryFromIntError
impl From<()> for Reject
Mapped to i32::MIN + 1.
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<NonZeroI32> for Reject
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<TryFromIntError> for TestStateError
impl From<TryFromIntError> for ParseError
impl From<Rc<str>> for Rc<[u8]>
impl From<Box<str, Global>> for String
impl From<NotPayableError> for Reject
The error code is i32::MIN + 12.
impl From<OwnedEntrypointName> for String
impl From<ParseError> for Reject
Mapped to i32::MIN + 2.
impl From<String> for Rc<str>
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 Vec<u8, Global>
impl From<Vec<u8, Global>> for TestStateEntryData
impl From<Vec<u8, Global>> for OwnedParameter
Convert the vector into a parameter as is.
impl From<CString> for Rc<CStr>
impl From<CString> for Box<CStr, Global>
impl From<CString> for Vec<u8, Global>
impl From<LayoutError> for TryReserveErrorKind
impl From<OsString> for Rc<OsStr>
impl From<OsString> for Box<OsStr, Global>
impl From<PathBuf> for Rc<Path>
impl From<PathBuf> for Box<Path, Global>
impl<'_> From<&'_ str> for Rc<str>
impl<'_> From<&'_ str> for Box<str, Global>
impl<'_> From<&'_ str> for Box<dyn Error + 'static, Global>
impl<'_> From<&'_ str> for String
impl<'_> From<&'_ str> for Vec<u8, Global>
impl<'_> From<&'_ String> for String
impl<'_> From<&'_ CStr> for Rc<CStr>
impl<'_> From<&'_ CStr> for Box<CStr, Global>
impl<'_> From<&'_ OsStr> for Rc<OsStr>
impl<'_> From<&'_ OsStr> for Box<OsStr, Global>
impl<'_> From<&'_ Path> for Rc<Path>
impl<'_> From<&'_ Path> for Box<Path, Global>
impl<'_> From<&'_ mut str> for String
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 Rc<[T]> where
T: Clone,
impl<'_, T> From<&'_ [T]> for Box<[T], Global> where
T: Copy,
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<Cow<'a, str>> for Box<dyn Error + 'static, Global>
impl<'a> From<Cow<'a, str>> for String
impl<'a> From<&'a [u8]> for Parameter<'a>
impl<'a> From<EntrypointName<'a>> for OwnedEntrypointName
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, 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<Cow<'a, [T]>> for Vec<T, Global> where
[T]: ToOwned,
<[T] as ToOwned>::Owned == Vec<T, Global>,
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<K, V, const N: usize> From<[(K, V); N]> for HashMap<K, V, RandomState> where
K: Eq + Hash,
impl<T> From<CallContractError<T>> for Reject
AmountTooLarge is i32::MIN + 15, MissingAccount is i32::MIN + 16, MissingContract is i32::MIN + 17, MissingEntrypoint is i32::MIN + 18, MessageFailed is i32::MIN + 19, LogicReject is i32::MIN + 20, Trap is i32::MIN + 21.
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.