Trait holochain_types::prelude::TryFrom 1.34.0[−][src]
Expand description
Simple and safe type conversions that may fail in a controlled
way under some circumstances. It is the reciprocal of TryInto
.
This is useful when you are doing a type conversion that may
trivially succeed but may also need special handling.
For example, there is no way to convert an i64
into an i32
using the From
trait, because an i64
may contain a value
that an i32
cannot represent and so the conversion would lose data.
This might be handled by truncating the i64
to an i32
(essentially
giving the i64
’s value modulo i32::MAX
) or by simply returning
i32::MAX
, or by some other method. The From
trait is intended
for perfect conversions, so the TryFrom
trait informs the
programmer when a type conversion could go bad and lets them
decide how to handle it.
Generic Implementations
TryFrom<T> for U
impliesTryInto
<U> for T
try_from
is reflexive, which means thatTryFrom<T> for T
is implemented and cannot fail – the associatedError
type for callingT::try_from()
on a value of typeT
isInfallible
. When the!
type is stabilizedInfallible
and!
will be equivalent.
TryFrom<T>
can be implemented as follows:
use std::convert::TryFrom;
struct GreaterThanZero(i32);
impl TryFrom<i32> for GreaterThanZero {
type Error = &'static str;
fn try_from(value: i32) -> Result<Self, Self::Error> {
if value <= 0 {
Err("GreaterThanZero only accepts value superior than zero!")
} else {
Ok(GreaterThanZero(value))
}
}
}
Examples
As described, i32
implements TryFrom<
i64
>
:
use std::convert::TryFrom;
let big_number = 1_000_000_000_000i64;
// Silently truncates `big_number`, requires detecting
// and handling the truncation after the fact.
let smaller_number = big_number as i32;
assert_eq!(smaller_number, -727379968);
// Returns an error because `big_number` is too big to
// fit in an `i32`.
let try_smaller_number = i32::try_from(big_number);
assert!(try_smaller_number.is_err());
// Returns `Ok(3)`.
let try_successful_smaller_number = i32::try_from(3);
assert!(try_successful_smaller_number.is_ok());
Associated Types
Required methods
Implementations on Foreign Types
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI8>>::Error>
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI8>>::Error>
Attempts to convert NonZeroI8
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroU64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI8>>::Error>
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI8>>::Error>
Attempts to convert NonZeroI8
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroI64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: isize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<isize>>::Error>
pub fn try_from(
value: isize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<isize>>::Error>
Attempts to convert isize
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroI128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU16>>::Error>
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU16>>::Error>
Attempts to convert NonZeroU16
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroU8
.
type Error = TryFromIntError
Attempts to convert u32
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU16>>::Error>
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU16>>::Error>
Attempts to convert NonZeroU16
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroU64
.
type Error = TryFromIntError
type Error = TryFromSliceError
Attempts to convert i32
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroI64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroI64
.
type Error = TryFromIntError
Attempts to convert u64
to NonZeroU64
.
type Error = TryFromIntError
Attempts to convert i64
to NonZeroI64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroU64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroU128
.
type Error = TryFromIntError
Attempts to convert u16
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroI64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU16>>::Error>
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU16>>::Error>
Attempts to convert NonZeroU16
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI64, <NonZeroI64 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroI64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU16>>::Error>
pub fn try_from(
value: NonZeroU16
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU16>>::Error>
Attempts to convert NonZeroU16
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroU16
.
type Error = TryFromIntError
type Error = TryFromSliceError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI8>>::Error>
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI8>>::Error>
Attempts to convert NonZeroI8
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroU64
.
type Error = TryFromIntError
Attempts to convert i16
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroU64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroU64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: usize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<usize>>::Error>
pub fn try_from(
value: usize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<usize>>::Error>
Attempts to convert usize
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroU8
.
type Error = TryFromIntError
Attempts to convert u128
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU32>>::Error>
pub fn try_from(
value: NonZeroU32
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroU32>>::Error>
Attempts to convert NonZeroU32
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI16>>::Error>
pub fn try_from(
value: NonZeroI16
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI16>>::Error>
Attempts to convert NonZeroI16
to NonZeroI8
.
type Error = TryFromIntError
type Error = TryFromSliceError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroI128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI32>>::Error>
pub fn try_from(
value: NonZeroI32
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroI32>>::Error>
Attempts to convert NonZeroI32
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroUsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroIsize, <NonZeroIsize as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroIsize
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI128, <NonZeroI128 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroI128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU8, <NonZeroU8 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroU8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroI32, <NonZeroI32 as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroI32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI8>>::Error>
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI8>>::Error>
Attempts to convert NonZeroI8
to NonZeroU64
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU128>>::Error>
pub fn try_from(
value: NonZeroU128
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroU128>>::Error>
Attempts to convert NonZeroU128
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroIsize>>::Error>
pub fn try_from(
value: NonZeroIsize
) -> Result<NonZeroUsize, <NonZeroUsize as TryFrom<NonZeroIsize>>::Error>
Attempts to convert NonZeroIsize
to NonZeroUsize
.
type Error = TryFromIntError
Attempts to convert i128
to NonZeroI128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI64>>::Error>
pub fn try_from(
value: NonZeroI64
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI64>>::Error>
Attempts to convert NonZeroI64
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroI16, <NonZeroI16 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroI16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU64>>::Error>
pub fn try_from(
value: NonZeroU64
) -> Result<NonZeroU16, <NonZeroU16 as TryFrom<NonZeroU64>>::Error>
Attempts to convert NonZeroU64
to NonZeroU16
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroUsize>>::Error>
pub fn try_from(
value: NonZeroUsize
) -> Result<NonZeroU32, <NonZeroU32 as TryFrom<NonZeroUsize>>::Error>
Attempts to convert NonZeroUsize
to NonZeroU32
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI8>>::Error>
pub fn try_from(
value: NonZeroI8
) -> Result<NonZeroU128, <NonZeroU128 as TryFrom<NonZeroI8>>::Error>
Attempts to convert NonZeroI8
to NonZeroU128
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroI8, <NonZeroI8 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroI8
.
type Error = TryFromIntError
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI128>>::Error>
pub fn try_from(
value: NonZeroI128
) -> Result<NonZeroU64, <NonZeroU64 as TryFrom<NonZeroI128>>::Error>
Attempts to convert NonZeroI128
to NonZeroU64
.
type Error = TryFromIntError
Gets the entire contents of the Vec<T>
as an array,
if its size exactly matches that of the requested array.
Examples
use std::convert::TryInto;
assert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3]));
assert_eq!(<Vec<i32>>::new().try_into(), Ok([]));
If the length doesn’t match, the input comes back in Err
:
use std::convert::TryInto;
let r: Result<[i32; 4], _> = (0..10).collect::<Vec<_>>().try_into();
assert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
If you’re fine with just getting a prefix of the Vec<T>
,
you can call .truncate(N)
first.
use std::convert::TryInto;
let mut v = String::from("hello world").into_bytes();
v.sort();
v.truncate(2);
let [a, b]: [_; 2] = v.try_into().unwrap();
assert_eq!(a, b' ');
assert_eq!(b, b'd');
type Error = SerializedBytesError
impl<'a, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> TryFrom<&'a Row<'a>> for (B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
B: FromSql,
C: FromSql,
D: FromSql,
E: FromSql,
F: FromSql,
G: FromSql,
H: FromSql,
I: FromSql,
J: FromSql,
K: FromSql,
L: FromSql,
M: FromSql,
N: FromSql,
O: FromSql,
P: FromSql,
impl<'a, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> TryFrom<&'a Row<'a>> for (B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
B: FromSql,
C: FromSql,
D: FromSql,
E: FromSql,
F: FromSql,
G: FromSql,
H: FromSql,
I: FromSql,
J: FromSql,
K: FromSql,
L: FromSql,
M: FromSql,
N: FromSql,
O: FromSql,
P: FromSql,
impl<'a, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> TryFrom<&'a Row<'a>> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: FromSql,
B: FromSql,
C: FromSql,
D: FromSql,
E: FromSql,
F: FromSql,
G: FromSql,
H: FromSql,
I: FromSql,
J: FromSql,
K: FromSql,
L: FromSql,
M: FromSql,
N: FromSql,
O: FromSql,
P: FromSql,
impl<'a, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P> TryFrom<&'a Row<'a>> for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) where
A: FromSql,
B: FromSql,
C: FromSql,
D: FromSql,
E: FromSql,
F: FromSql,
G: FromSql,
H: FromSql,
I: FromSql,
J: FromSql,
K: FromSql,
L: FromSql,
M: FromSql,
N: FromSql,
O: FromSql,
P: FromSql,
Try to create an ArrayVec
from a slice. This will return an error if the slice was too big to
fit.
use arrayvec::ArrayVec;
use std::convert::TryInto as _;
let array: ArrayVec<[_; 4]> = (&[1, 2, 3] as &[_]).try_into().unwrap();
assert_eq!(array.len(), 3);
assert_eq!(array.capacity(), 4);
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigInt>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<()>
type Error = TryFromBigIntError<BigUint>
type Error = TryFromBigIntError<BigInt>
impl TryFrom<SerializedBytes> for WasmError
impl TryFrom<SerializedBytes> for WasmError
type Error = SerializedBytesError
pub fn try_from(sb: SerializedBytes) -> Result<WasmError, SerializedBytesError>
pub fn try_from(
stream: UnixDatagram
) -> Result<UnixDatagram, <UnixDatagram as TryFrom<UnixDatagram>>::Error>
pub fn try_from(
stream: UnixDatagram
) -> Result<UnixDatagram, <UnixDatagram as TryFrom<UnixDatagram>>::Error>
Consumes stream, returning the Tokio I/O object.
This is equivalent to
UnixDatagram::from_std(stream)
.
Consumes stream, returning the tokio I/O object.
This is equivalent to
UnixStream::from_std(stream)
.
Consumes stream, returning the tokio I/O object.
This is equivalent to
UnixListener::from_std(stream)
.
pub fn try_from(
stream: TcpListener
) -> Result<TcpListener, <TcpListener as TryFrom<TcpListener>>::Error>
pub fn try_from(
stream: TcpListener
) -> Result<TcpListener, <TcpListener as TryFrom<TcpListener>>::Error>
Consumes stream, returning the tokio I/O object.
This is equivalent to
TcpListener::from_std(stream)
.
type Error = InvalidUri
type Error = InvalidUri
pub fn try_from(
s: &String
) -> Result<PathAndQuery, <PathAndQuery as TryFrom<&'_ String>>::Error>
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
type Error = InvalidHeaderValue
pub fn try_from(
s: &'a String
) -> Result<HeaderValue, <HeaderValue as TryFrom<&'a String>>::Error>
type Error = InvalidUri
Try to convert a HashMap
into a HeaderMap
.
Examples
use std::collections::HashMap;
use std::convert::TryInto;
use http::HeaderMap;
let mut map = HashMap::new();
map.insert("X-Custom-Header".to_string(), "my value".to_string());
let headers: HeaderMap = (&map).try_into().expect("valid headers");
assert_eq!(headers["X-Custom-Header"], "my value");