pub trait TryFrom<T>: Sized {
type Error;
// Required method
fn try_from(value: T) -> Result<Self, Self::Error>;
}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 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 UimpliesTryInto<U> for Ttry_fromis reflexive, which means thatTryFrom<T> for Tis implemented and cannot fail – the associatedErrortype for callingT::try_from()on a value of typeTisInfallible. When the!type is stabilizedInfallibleand!will be equivalent.
Prefer using TryInto over TryFrom when specifying trait bounds on a generic function
to ensure that types that only implement TryInto can be used as well.
TryFrom<T> can be implemented as follows:
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 values greater than zero!")
} else {
Ok(GreaterThanZero(value))
}
}
}§Examples
As described, i32 implements TryFrom<i64>:
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());Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
§impl TryFrom<&PrivateKeyDer<'_>> for KeyPair
Available on crate feature crypto only.
impl TryFrom<&PrivateKeyDer<'_>> for KeyPair
crypto only.§impl TryFrom<&str> for NonEmptyStr
impl TryFrom<&str> for NonEmptyStr
type Error = EmptyStrErr
§impl TryFrom<&HeaderName> for ClientHint
impl TryFrom<&HeaderName> for ClientHint
§impl TryFrom<&HeaderValue> for Host
Available on crate feature http only.
impl TryFrom<&HeaderValue> for Host
http only.§impl TryFrom<&HeaderValue> for DnsResolveMode
impl TryFrom<&HeaderValue> for DnsResolveMode
§impl TryFrom<&HeaderValue> for SocketAddress
Available on crate feature http only.
impl TryFrom<&HeaderValue> for SocketAddress
http only.§impl TryFrom<&HeaderValue> for Forwarded
Available on crate feature http only.
impl TryFrom<&HeaderValue> for Forwarded
http only.§impl TryFrom<&HeaderValue> for ForwardedElement
Available on crate feature http only.
impl TryFrom<&HeaderValue> for ForwardedElement
http only.§impl TryFrom<&ClientConfig> for TlsConnectorDataBuilder
impl TryFrom<&ClientConfig> for TlsConnectorDataBuilder
§impl TryFrom<&String> for PathAndQuery
impl TryFrom<&String> for PathAndQuery
type Error = InvalidUri
§impl TryFrom<&String> for NonEmptyStr
impl TryFrom<&String> for NonEmptyStr
type Error = EmptyStrErr
§impl TryFrom<&Arc<ClientConfig>> for TlsConnectorDataBuilder
impl TryFrom<&Arc<ClientConfig>> for TlsConnectorDataBuilder
§impl TryFrom<&PrivatePkcs8KeyDer<'_>> for KeyPair
Available on crate feature crypto only.
impl TryFrom<&PrivatePkcs8KeyDer<'_>> for KeyPair
crypto only.§impl TryFrom<&[u8]> for ReasonPhrase
impl TryFrom<&[u8]> for ReasonPhrase
type Error = InvalidReasonPhrase
§impl TryFrom<HttpVersion> for Version
impl TryFrom<HttpVersion> for Version
type Error = HttpVersion
§impl TryFrom<ClientAuth> for ConnectorConfigClientAuth
impl TryFrom<ClientAuth> for ConnectorConfigClientAuth
§impl TryFrom<JWA> for &'static EcdsaVerificationAlgorithm
impl TryFrom<JWA> for &'static EcdsaVerificationAlgorithm
1.59.0 (const: unstable) · Source§impl TryFrom<char> for u8
Maps a char with a code point from U+0000 to U+00FF (inclusive) to a byte in 0x00..=0xFF with
the same value, failing if the code point is greater than U+00FF.
impl TryFrom<char> for u8
Maps a char with a code point from U+0000 to U+00FF (inclusive) to a byte in 0x00..=0xFF with
the same value, failing if the code point is greater than U+00FF.
See impl From<u8> for char for details on the encoding.
type Error = TryFromCharError
1.74.0 (const: unstable) · Source§impl TryFrom<char> for u16
Maps a char with a code point from U+0000 to U+FFFF (inclusive) to a u16 in 0x0000..=0xFFFF
with the same value, failing if the code point is greater than U+FFFF.
impl TryFrom<char> for u16
Maps a char with a code point from U+0000 to U+FFFF (inclusive) to a u16 in 0x0000..=0xFFFF
with the same value, failing if the code point is greater than U+FFFF.
This corresponds to the UCS-2 encoding, as specified in ISO/IEC 10646:2003.
type Error = TryFromCharError
1.94.0 (const: unstable) · Source§impl TryFrom<char> for usize
Maps a char with a code point from U+0000 to U+10FFFF (inclusive) to a usize in
0x0000..=0x10FFFF with the same value, failing if the final value is unrepresentable by
usize.
impl TryFrom<char> for usize
Maps a char with a code point from U+0000 to U+10FFFF (inclusive) to a usize in
0x0000..=0x10FFFF with the same value, failing if the final value is unrepresentable by
usize.
Generally speaking, this conversion can be seen as obtaining the character’s corresponding UTF-32 code point to the extent representable by pointer addresses.
type Error = TryFromCharError
1.46.0 (const: unstable) · Source§impl TryFrom<i8> for NonZero<i8>
impl TryFrom<i8> for NonZero<i8>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<i16> for NonZero<i16>
impl TryFrom<i16> for NonZero<i16>
type Error = TryFromIntError
Source§impl TryFrom<i32> for Cardinality
impl TryFrom<i32> for Cardinality
type Error = UnknownEnumValue
Source§impl TryFrom<i32> for OptimizeMode
impl TryFrom<i32> for OptimizeMode
type Error = UnknownEnumValue
Source§impl TryFrom<i32> for IdempotencyLevel
impl TryFrom<i32> for IdempotencyLevel
type Error = UnknownEnumValue
§impl TryFrom<i32> for ServingStatus
impl TryFrom<i32> for ServingStatus
type Error = UnknownEnumValue
1.46.0 (const: unstable) · Source§impl TryFrom<i32> for NonZero<i32>
impl TryFrom<i32> for NonZero<i32>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<i64> for NonZero<i64>
impl TryFrom<i64> for NonZero<i64>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<i128> for NonZero<i128>
impl TryFrom<i128> for NonZero<i128>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<isize> for NonZero<isize>
impl TryFrom<isize> for NonZero<isize>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<u8> for NonZero<u8>
impl TryFrom<u8> for NonZero<u8>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<u16> for NonZero<u16>
impl TryFrom<u16> for NonZero<u16>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<u32> for NonZero<u32>
impl TryFrom<u32> for NonZero<u32>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<u64> for NonZero<u64>
impl TryFrom<u64> for NonZero<u64>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<u128> for NonZero<u128>
impl TryFrom<u128> for NonZero<u128>
type Error = TryFromIntError
1.46.0 (const: unstable) · Source§impl TryFrom<usize> for NonZero<usize>
impl TryFrom<usize> for NonZero<usize>
type Error = TryFromIntError
§impl TryFrom<Bytes> for ReasonPhrase
impl TryFrom<Bytes> for ReasonPhrase
type Error = InvalidReasonPhrase
§impl TryFrom<Vec<u8>> for PrivateKeyDer<'_>
Available on crate feature alloc only.
impl TryFrom<Vec<u8>> for PrivateKeyDer<'_>
alloc only.§impl TryFrom<Vec<u8>> for ReasonPhrase
impl TryFrom<Vec<u8>> for ReasonPhrase
type Error = InvalidReasonPhrase
§impl TryFrom<Vec<u8>> for HeaderName
impl TryFrom<Vec<u8>> for HeaderName
type Error = InvalidHeaderName
§impl TryFrom<Vec<u8>> for HeaderValue
impl TryFrom<Vec<u8>> for HeaderValue
type Error = InvalidHeaderValue
§impl TryFrom<Vec<u8>> for PathAndQuery
impl TryFrom<Vec<u8>> for PathAndQuery
type Error = InvalidUri
Source§impl TryFrom<Timestamp> for SystemTime
Available on crate feature std only.
impl TryFrom<Timestamp> for SystemTime
std only.type Error = TimestampError
§impl TryFrom<SecWebSocketKey> for SecWebSocketAccept
impl TryFrom<SecWebSocketKey> for SecWebSocketAccept
§impl TryFrom<ExecuteScript> for Event<ExecuteScript>
impl TryFrom<ExecuteScript> for Event<ExecuteScript>
type Error = EventBuildError
§impl TryFrom<PatchElements> for Event<PatchElements>
impl TryFrom<PatchElements> for Event<PatchElements>
type Error = EventBuildError
§impl TryFrom<HeaderName> for ClientHint
impl TryFrom<HeaderName> for ClientHint
§impl TryFrom<HeaderValue> for Host
Available on crate feature http only.
impl TryFrom<HeaderValue> for Host
http only.§impl TryFrom<HeaderValue> for SocketAddress
Available on crate feature http only.
impl TryFrom<HeaderValue> for SocketAddress
http only.§impl TryFrom<HeaderValue> for Forwarded
Available on crate feature http only.
impl TryFrom<HeaderValue> for Forwarded
http only.§impl TryFrom<HeaderValue> for ForwardedElement
Available on crate feature http only.
impl TryFrom<HeaderValue> for ForwardedElement
http only.§impl TryFrom<ClientHello> for TlsConnectorDataBuilder
impl TryFrom<ClientHello> for TlsConnectorDataBuilder
§impl TryFrom<ServerConfig> for TlsAcceptorData
impl TryFrom<ServerConfig> for TlsAcceptorData
Source§impl TryFrom<ByteString> for String
impl TryFrom<ByteString> for String
type Error = FromUtf8Error
§impl TryFrom<String> for ServerName<'static>
Available on crate feature alloc only.
impl TryFrom<String> for ServerName<'static>
alloc only.type Error = InvalidDnsNameError
§impl TryFrom<String> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
impl TryFrom<String> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
If the argument contains invalid metadata value characters, an error is
returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytes to create a MetadataValue that includes opaque octets
(128-255).
type Error = InvalidMetadataValue
§impl TryFrom<String> for ReasonPhrase
impl TryFrom<String> for ReasonPhrase
type Error = InvalidReasonPhrase
§impl TryFrom<String> for HeaderName
impl TryFrom<String> for HeaderName
type Error = InvalidHeaderName
§impl TryFrom<String> for HeaderValue
impl TryFrom<String> for HeaderValue
type Error = InvalidHeaderValue
§impl TryFrom<String> for PathAndQuery
impl TryFrom<String> for PathAndQuery
type Error = InvalidUri
§impl TryFrom<String> for NonEmptyStr
impl TryFrom<String> for NonEmptyStr
type Error = EmptyStrErr
§impl TryFrom<String> for DnsName<'static>
Available on crate feature alloc only.
impl TryFrom<String> for DnsName<'static>
alloc only.type Error = InvalidDnsNameError
§impl TryFrom<ArcStr> for NonEmptyStr
impl TryFrom<ArcStr> for NonEmptyStr
type Error = EmptyStrErr
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<u8>
impl TryFrom<NonZero<i8>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<u16>
impl TryFrom<NonZero<i8>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<u32>
impl TryFrom<NonZero<i8>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<u64>
impl TryFrom<NonZero<i8>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<u128>
impl TryFrom<NonZero<i8>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i8>> for NonZero<usize>
impl TryFrom<NonZero<i8>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<i8>
impl TryFrom<NonZero<i16>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<u8>
impl TryFrom<NonZero<i16>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<u16>
impl TryFrom<NonZero<i16>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<u32>
impl TryFrom<NonZero<i16>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<u64>
impl TryFrom<NonZero<i16>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<u128>
impl TryFrom<NonZero<i16>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i16>> for NonZero<usize>
impl TryFrom<NonZero<i16>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<i8>
impl TryFrom<NonZero<i32>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<i16>
impl TryFrom<NonZero<i32>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<isize>
impl TryFrom<NonZero<i32>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<u8>
impl TryFrom<NonZero<i32>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<u16>
impl TryFrom<NonZero<i32>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<u32>
impl TryFrom<NonZero<i32>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<u64>
impl TryFrom<NonZero<i32>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<u128>
impl TryFrom<NonZero<i32>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i32>> for NonZero<usize>
impl TryFrom<NonZero<i32>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<i8>
impl TryFrom<NonZero<i64>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<i16>
impl TryFrom<NonZero<i64>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<i32>
impl TryFrom<NonZero<i64>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<isize>
impl TryFrom<NonZero<i64>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<u8>
impl TryFrom<NonZero<i64>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<u16>
impl TryFrom<NonZero<i64>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<u32>
impl TryFrom<NonZero<i64>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<u64>
impl TryFrom<NonZero<i64>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<u128>
impl TryFrom<NonZero<i64>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i64>> for NonZero<usize>
impl TryFrom<NonZero<i64>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<i8>
impl TryFrom<NonZero<i128>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<i16>
impl TryFrom<NonZero<i128>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<i32>
impl TryFrom<NonZero<i128>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<i64>
impl TryFrom<NonZero<i128>> for NonZero<i64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<isize>
impl TryFrom<NonZero<i128>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<u8>
impl TryFrom<NonZero<i128>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<u16>
impl TryFrom<NonZero<i128>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<u32>
impl TryFrom<NonZero<i128>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<u64>
impl TryFrom<NonZero<i128>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<u128>
impl TryFrom<NonZero<i128>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<i128>> for NonZero<usize>
impl TryFrom<NonZero<i128>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<i8>
impl TryFrom<NonZero<isize>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<i16>
impl TryFrom<NonZero<isize>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<i32>
impl TryFrom<NonZero<isize>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<i64>
impl TryFrom<NonZero<isize>> for NonZero<i64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<i128>
impl TryFrom<NonZero<isize>> for NonZero<i128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<u8>
impl TryFrom<NonZero<isize>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<u16>
impl TryFrom<NonZero<isize>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<u32>
impl TryFrom<NonZero<isize>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<u64>
impl TryFrom<NonZero<isize>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<u128>
impl TryFrom<NonZero<isize>> for NonZero<u128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<isize>> for NonZero<usize>
impl TryFrom<NonZero<isize>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u8>> for NonZero<i8>
impl TryFrom<NonZero<u8>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u16>> for NonZero<i8>
impl TryFrom<NonZero<u16>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u16>> for NonZero<i16>
impl TryFrom<NonZero<u16>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u16>> for NonZero<isize>
impl TryFrom<NonZero<u16>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u16>> for NonZero<u8>
impl TryFrom<NonZero<u16>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<i8>
impl TryFrom<NonZero<u32>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<i16>
impl TryFrom<NonZero<u32>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<i32>
impl TryFrom<NonZero<u32>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<isize>
impl TryFrom<NonZero<u32>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<u8>
impl TryFrom<NonZero<u32>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<u16>
impl TryFrom<NonZero<u32>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u32>> for NonZero<usize>
impl TryFrom<NonZero<u32>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<i8>
impl TryFrom<NonZero<u64>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<i16>
impl TryFrom<NonZero<u64>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<i32>
impl TryFrom<NonZero<u64>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<i64>
impl TryFrom<NonZero<u64>> for NonZero<i64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<isize>
impl TryFrom<NonZero<u64>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<u8>
impl TryFrom<NonZero<u64>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<u16>
impl TryFrom<NonZero<u64>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<u32>
impl TryFrom<NonZero<u64>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u64>> for NonZero<usize>
impl TryFrom<NonZero<u64>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<i8>
impl TryFrom<NonZero<u128>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<i16>
impl TryFrom<NonZero<u128>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<i32>
impl TryFrom<NonZero<u128>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<i64>
impl TryFrom<NonZero<u128>> for NonZero<i64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<i128>
impl TryFrom<NonZero<u128>> for NonZero<i128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<isize>
impl TryFrom<NonZero<u128>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<u8>
impl TryFrom<NonZero<u128>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<u16>
impl TryFrom<NonZero<u128>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<u32>
impl TryFrom<NonZero<u128>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<u64>
impl TryFrom<NonZero<u128>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<u128>> for NonZero<usize>
impl TryFrom<NonZero<u128>> for NonZero<usize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<i8>
impl TryFrom<NonZero<usize>> for NonZero<i8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<i16>
impl TryFrom<NonZero<usize>> for NonZero<i16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<i32>
impl TryFrom<NonZero<usize>> for NonZero<i32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<i64>
impl TryFrom<NonZero<usize>> for NonZero<i64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<i128>
impl TryFrom<NonZero<usize>> for NonZero<i128>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<isize>
impl TryFrom<NonZero<usize>> for NonZero<isize>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<u8>
impl TryFrom<NonZero<usize>> for NonZero<u8>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<u16>
impl TryFrom<NonZero<usize>> for NonZero<u16>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<u32>
impl TryFrom<NonZero<usize>> for NonZero<u32>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<u64>
impl TryFrom<NonZero<usize>> for NonZero<u64>
type Error = TryFromIntError
1.49.0 (const: unstable) · Source§impl TryFrom<NonZero<usize>> for NonZero<u128>
impl TryFrom<NonZero<usize>> for NonZero<u128>
type Error = TryFromIntError
Source§impl TryFrom<Duration> for rama::http::grpc::protobuf::prost::types::Duration
impl TryFrom<Duration> for rama::http::grpc::protobuf::prost::types::Duration
type Error = DurationError
§impl TryFrom<Duration> for SignedDuration
Fallibly converts a std::time::Duration to a SignedDuration.
impl TryFrom<Duration> for SignedDuration
Fallibly converts a std::time::Duration to a SignedDuration.
§Errors
This fails when the duration’s second component exceeds i64::MAX.
§Examples
use std::time::Duration;
use jiff::SignedDuration;
let dur = Duration::new(5, 123_000_000);
let sdur = SignedDuration::try_from(dur)?;
assert_eq!(sdur, SignedDuration::new(5, 123_000_000));
let dur = Duration::new(i64::MAX as u64, 999_999_999);
let sdur = SignedDuration::try_from(dur)?;
assert_eq!(sdur, SignedDuration::new(i64::MAX, 999_999_999));
// Some failure cases:
assert!(SignedDuration::try_from(Duration::new(i64::MAX as u64 + 1, 0)).is_err());
assert!(SignedDuration::try_from(Duration::new(u64::MAX, 0)).is_err());
§impl TryFrom<Duration> for Span
Converts a std::time::Duration to a Span.
impl TryFrom<Duration> for Span
Converts a std::time::Duration to a Span.
The span returned from this conversion will only ever have non-zero units of seconds or smaller.
§Errors
This only fails when the given Duration overflows the maximum number of
seconds representable by a Span.
§Example
This shows a basic conversion:
use std::time::Duration;
use jiff::{Span, ToSpan};
let duration = Duration::new(86_400, 123_456_789);
let span = Span::try_from(duration)?;
// A duration-to-span conversion always results in a span with
// non-zero units no bigger than seconds.
assert_eq!(
span.fieldwise(),
86_400.seconds().milliseconds(123).microseconds(456).nanoseconds(789),
);
§Example: rounding
This example shows how to convert a Duration to a Span, and then round
it up to bigger units given a relative date:
use std::time::Duration;
use jiff::{civil::date, Span, SpanRound, ToSpan, Unit};
let duration = Duration::new(450 * 86_401, 0);
let span = Span::try_from(duration)?;
// We get back a simple span of just seconds:
assert_eq!(span.fieldwise(), Span::new().seconds(450 * 86_401));
// But we can balance it up to bigger units:
let options = SpanRound::new()
.largest(Unit::Year)
.relative(date(2024, 1, 1));
assert_eq!(
span.round(options)?,
1.year().months(2).days(25).minutes(7).seconds(30).fieldwise(),
);
§impl TryFrom<UnixDatagram> for UnixDatagram
impl TryFrom<UnixDatagram> for UnixDatagram
§impl TryFrom<UnixStream> for UnixStream
impl TryFrom<UnixStream> for UnixStream
Source§impl TryFrom<SystemTime> for uuid::timestamp::Timestamp
Available on crate feature std only.
impl TryFrom<SystemTime> for uuid::timestamp::Timestamp
std only.§impl TryFrom<SystemTime> for Timestamp
Available on crate feature std only.
impl TryFrom<SystemTime> for Timestamp
std only.§impl TryFrom<SystemTime> for Zoned
Available on crate feature std only.
impl TryFrom<SystemTime> for Zoned
std only.Source§impl TryFrom<DateTime> for rama::http::grpc::protobuf::prost::types::Timestamp
impl TryFrom<DateTime> for rama::http::grpc::protobuf::prost::types::Timestamp
type Error = TimestampError
§impl TryFrom<SignedDuration> for core::time::Duration
Fallibly converts a SignedDuration to a std::time::Duration.
impl TryFrom<SignedDuration> for core::time::Duration
Fallibly converts a SignedDuration to a std::time::Duration.
§Errors
This fails when the signed duration is negative.
§Examples
use std::time::Duration;
use jiff::SignedDuration;
let sdur = SignedDuration::new(5, 123_000_000);
let dur = Duration::try_from(sdur)?;
assert_eq!(dur, Duration::new(5, 123_000_000));
// Some failure cases:
assert!(Duration::try_from(SignedDuration::new(-5, 0)).is_err());
assert!(Duration::try_from(SignedDuration::new(-5, -1)).is_err());
assert!(Duration::try_from(SignedDuration::new(0, -1)).is_err());
§impl TryFrom<SignedDuration> for Offset
Converts a SignedDuration to a time zone offset.
impl TryFrom<SignedDuration> for Offset
Converts a SignedDuration to a time zone offset.
If the signed duration has fractional seconds, then it is automatically
rounded to the nearest second. (Because an Offset has only second
precision.)
§Errors
This returns an error if the duration overflows the limits of an Offset.
§Example
use jiff::{tz::{self, Offset}, SignedDuration};
let sdur = SignedDuration::from_secs(-5 * 60 * 60);
let offset = Offset::try_from(sdur)?;
assert_eq!(offset, tz::offset(-5));
// Sub-seconds results in rounded.
let sdur = SignedDuration::new(-5 * 60 * 60, -500_000_000);
let offset = Offset::try_from(sdur)?;
assert_eq!(offset, tz::Offset::from_seconds(-(5 * 60 * 60 + 1)).unwrap());
§impl TryFrom<SignedDuration> for Span
Converts a [SignedDuration] to a Span.
impl TryFrom<SignedDuration> for Span
Converts a [SignedDuration] to a Span.
The span returned from this conversion will only ever have non-zero units of seconds or smaller.
§Errors
This only fails when the given SignedDuration overflows the maximum
number of seconds representable by a Span.
§Example
This shows a basic conversion:
use jiff::{SignedDuration, Span, ToSpan};
let duration = SignedDuration::new(86_400, 123_456_789);
let span = Span::try_from(duration)?;
// A duration-to-span conversion always results in a span with
// non-zero units no bigger than seconds.
assert_eq!(
span.fieldwise(),
86_400.seconds().milliseconds(123).microseconds(456).nanoseconds(789),
);
§Example: rounding
This example shows how to convert a SignedDuration to a Span, and then
round it up to bigger units given a relative date:
use jiff::{civil::date, SignedDuration, Span, SpanRound, ToSpan, Unit};
let duration = SignedDuration::new(450 * 86_401, 0);
let span = Span::try_from(duration)?;
// We get back a simple span of just seconds:
assert_eq!(span.fieldwise(), Span::new().seconds(450 * 86_401));
// But we can balance it up to bigger units:
let options = SpanRound::new()
.largest(Unit::Year)
.relative(date(2024, 1, 1));
assert_eq!(
span.round(options)?,
1.year().months(2).days(25).minutes(7).seconds(30).fieldwise(),
);
§impl TryFrom<Span> for core::time::Duration
Converts a Span to a std::time::Duration.
impl TryFrom<Span> for core::time::Duration
Converts a Span to a std::time::Duration.
§Errors
This can fail for only two reasons:
- The span is negative. This is an error because a
std::time::Durationis unsigned.) - The span has any non-zero units greater than hours. This is an error because it’s impossible to determine the length of, e.g., a month without a reference date.
This can never result in overflow because a Duration can represent a
bigger span of time than Span when limited to units of hours or lower.
If you need to convert a Span to a Duration that has non-zero
units bigger than hours, then please use [Span::to_duration] with a
corresponding relative date.
§Example: maximal span
This example shows the maximum possible span using units of hours or
smaller, and the corresponding Duration value:
use std::time::Duration;
use jiff::Span;
let sp = Span::new()
.hours(175_307_616)
.minutes(10_518_456_960i64)
.seconds(631_107_417_600i64)
.milliseconds(631_107_417_600_000i64)
.microseconds(631_107_417_600_000_000i64)
.nanoseconds(9_223_372_036_854_775_807i64);
let duration = Duration::try_from(sp)?;
assert_eq!(duration, Duration::new(3_164_760_460_036, 854_775_807));
§Example: converting a negative span
Since a Span is signed and a Duration is unsigned, converting
a negative Span to Duration will always fail. One can use
[Span::signum] to get the sign of the span and [Span::abs] to make the
span positive before converting it to a Duration:
use std::time::Duration;
use jiff::{Span, ToSpan};
let span = -86_400.seconds().nanoseconds(1);
let (sign, duration) = (span.signum(), Duration::try_from(span.abs())?);
assert_eq!((sign, duration), (-1, Duration::new(86_400, 1)));
§impl TryFrom<Span> for SignedDuration
Converts a Span to a [SignedDuration].
impl TryFrom<Span> for SignedDuration
Converts a Span to a [SignedDuration].
§Errors
This can fail for only when the span has any non-zero units greater than hours. This is an error because it’s impossible to determine the length of, e.g., a month without a reference date.
This can never result in overflow because a SignedDuration can represent
a bigger span of time than Span when limited to units of hours or lower.
If you need to convert a Span to a SignedDuration that has non-zero
units bigger than hours, then please use [Span::to_duration] with a
corresponding relative date.
§Example: maximal span
This example shows the maximum possible span using units of hours or
smaller, and the corresponding SignedDuration value:
use jiff::{SignedDuration, Span};
let sp = Span::new()
.hours(175_307_616)
.minutes(10_518_456_960i64)
.seconds(631_107_417_600i64)
.milliseconds(631_107_417_600_000i64)
.microseconds(631_107_417_600_000_000i64)
.nanoseconds(9_223_372_036_854_775_807i64);
let duration = SignedDuration::try_from(sp)?;
assert_eq!(duration, SignedDuration::new(3_164_760_460_036, 854_775_807));
§impl<'a> TryFrom<&'a EdnsOption> for Vec<u8>
impl<'a> TryFrom<&'a EdnsOption> for Vec<u8>
type Error = ProtoError
§impl<'a> TryFrom<&'a DecryptionContext> for &'a [u8]
impl<'a> TryFrom<&'a DecryptionContext> for &'a [u8]
type Error = Unspecified
§impl<'a> TryFrom<&'a EncryptionContext> for &'a [u8]
impl<'a> TryFrom<&'a EncryptionContext> for &'a [u8]
type Error = Unspecified
§impl<'a> TryFrom<&'a str> for ServerName<'a>
Attempt to make a ServerName from a string by parsing as a DNS name or IP address.
impl<'a> TryFrom<&'a str> for ServerName<'a>
Attempt to make a ServerName from a string by parsing as a DNS name or IP address.
type Error = InvalidDnsNameError
§impl<'a> TryFrom<&'a str> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
impl<'a> TryFrom<&'a str> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
If the argument contains invalid metadata value characters, an error is
returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytes to create a MetadataValue that includes opaque octets
(128-255).
type Error = InvalidMetadataValue
§impl<'a> TryFrom<&'a str> for HeaderName
impl<'a> TryFrom<&'a str> for HeaderName
type Error = InvalidHeaderName
§impl<'a> TryFrom<&'a str> for HeaderValue
impl<'a> TryFrom<&'a str> for HeaderValue
type Error = InvalidHeaderValue
§impl<'a> TryFrom<&'a str> for PathAndQuery
impl<'a> TryFrom<&'a str> for PathAndQuery
type Error = InvalidUri
§impl<'a> TryFrom<&'a str> for rama::proxy::haproxy::protocol::v1::Header<'a>
impl<'a> TryFrom<&'a str> for rama::proxy::haproxy::protocol::v1::Header<'a>
type Error = ParseError
§impl<'a> TryFrom<&'a ClientSubnet> for Vec<u8>
impl<'a> TryFrom<&'a ClientSubnet> for Vec<u8>
type Error = ProtoError
§impl<'a> TryFrom<&'a String> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
impl<'a> TryFrom<&'a String> for MetadataValue<Ascii>
Attempt to convert a string to a MetadataValue<Ascii>.
If the argument contains invalid metadata value characters, an error is
returned. Only visible ASCII characters (32-127) are permitted. Use
from_bytes to create a MetadataValue that includes opaque octets
(128-255).
type Error = InvalidMetadataValue
§impl<'a> TryFrom<&'a String> for HeaderName
impl<'a> TryFrom<&'a String> for HeaderName
type Error = InvalidHeaderName
§impl<'a> TryFrom<&'a String> for HeaderValue
impl<'a> TryFrom<&'a String> for HeaderValue
type Error = InvalidHeaderValue
§impl<'a> TryFrom<&'a CertificateDer<'a>> for ParsedCertificate<'a>
impl<'a> TryFrom<&'a CertificateDer<'a>> for ParsedCertificate<'a>
§impl<'a> TryFrom<&'a CertificateDer<'a>> for EndEntityCert<'a>
impl<'a> TryFrom<&'a CertificateDer<'a>> for EndEntityCert<'a>
§impl<'a> TryFrom<&'a SubjectPublicKeyInfoDer<'a>> for RawPublicKeyEntity<'a>
impl<'a> TryFrom<&'a SubjectPublicKeyInfoDer<'a>> for RawPublicKeyEntity<'a>
§impl<'a> TryFrom<&'a [u8]> for ServerName<'a>
impl<'a> TryFrom<&'a [u8]> for ServerName<'a>
type Error = InvalidDnsNameError
§impl<'a> TryFrom<&'a [u8]> for ClientSubnet
impl<'a> TryFrom<&'a [u8]> for ClientSubnet
type Error = DecodeError
§impl<'a> TryFrom<&'a [u8]> for NSIDPayload
impl<'a> TryFrom<&'a [u8]> for NSIDPayload
type Error = DecodeError
§impl<'a> TryFrom<&'a [u8]> for HeaderName
impl<'a> TryFrom<&'a [u8]> for HeaderName
type Error = InvalidHeaderName
§impl<'a> TryFrom<&'a [u8]> for HeaderValue
impl<'a> TryFrom<&'a [u8]> for HeaderValue
type Error = InvalidHeaderValue
§impl<'a> TryFrom<&'a [u8]> for PathAndQuery
impl<'a> TryFrom<&'a [u8]> for PathAndQuery
type Error = InvalidUri
§impl<'a> TryFrom<&'a [u8]> for rama::proxy::haproxy::protocol::v1::Header<'a>
impl<'a> TryFrom<&'a [u8]> for rama::proxy::haproxy::protocol::v1::Header<'a>
type Error = BinaryParseError
§impl<'a> TryFrom<&'a [u8]> for rama::proxy::haproxy::protocol::v2::Header<'a>
impl<'a> TryFrom<&'a [u8]> for rama::proxy::haproxy::protocol::v2::Header<'a>
type Error = ParseError
§impl<'a> TryFrom<(EdnsCode, &'a [u8])> for EdnsOption
only the supported extensions are listed right now.
impl<'a> TryFrom<(EdnsCode, &'a [u8])> for EdnsOption
only the supported extensions are listed right now.
type Error = DecodeError
§impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::PrintableString<'a>
impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::PrintableString<'a>
§impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::TeletexString<'a>
impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::TeletexString<'a>
§impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::UniversalString<'a>
impl<'a> TryFrom<Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::UniversalString<'a>
§impl<'a, 'b> TryFrom<&'b AlgorithmIdentifier<'a>> for SignatureAlgorithm<'a>
impl<'a, 'b> TryFrom<&'b AlgorithmIdentifier<'a>> for SignatureAlgorithm<'a>
§impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::Ia5String<'a>
impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::Ia5String<'a>
§impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::PrintableString<'a>
impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::PrintableString<'a>
§impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::TeletexString<'a>
impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::TeletexString<'a>
§impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::UniversalString<'a>
impl<'a, 'b> TryFrom<&'b Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::UniversalString<'a>
§impl<'a, 'b, E, T, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
impl<'a, 'b, E, T, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
§impl<'a, 'b, T, E, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
impl<'a, 'b, T, E, const CLASS: u8, const TAG: u32> TryFrom<&'b Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
§impl<'a, 'r> TryFrom<&'r Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::BmpString<'a>
impl<'a, 'r> TryFrom<&'r Any<'a>> for rama::crypto::dep::x509_parser::prelude::asn1_rs::BmpString<'a>
§impl<'a, K, V, S, T> TryFrom<&'a HashMap<K, V, S>> for HeaderMap<T>
Try to convert a HashMap into a HeaderMap.
impl<'a, K, V, S, T> TryFrom<&'a HashMap<K, V, S>> for HeaderMap<T>
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");§impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Explicit, CLASS, TAG>
§impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
impl<'a, T, E, const CLASS: u8, const TAG: u32> TryFrom<Any<'a>> for TaggedValue<T, E, Implicit, CLASS, TAG>
1.34.0 (const: unstable) · Source§impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N]
Tries to create an array ref &[T; N] from a slice ref &[T]. Succeeds if
slice.len() == N.
impl<'a, T, const N: usize> TryFrom<&'a [T]> for &'a [T; N]
Tries to create an array ref &[T; N] from a slice ref &[T]. Succeeds if
slice.len() == N.
let bytes: [u8; 3] = [1, 0, 2];
let bytes_head: &[u8; 2] = <&[u8; 2]>::try_from(&bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(*bytes_head));
let bytes_tail: &[u8; 2] = bytes[1..3].try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(*bytes_tail));type Error = TryFromSliceError
1.34.0 (const: unstable) · Source§impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N]
Tries to create a mutable array ref &mut [T; N] from a mutable slice ref
&mut [T]. Succeeds if slice.len() == N.
impl<'a, T, const N: usize> TryFrom<&'a mut [T]> for &'a mut [T; N]
Tries to create a mutable array ref &mut [T; N] from a mutable slice ref
&mut [T]. Succeeds if slice.len() == N.
let mut bytes: [u8; 3] = [1, 0, 2];
let bytes_head: &mut [u8; 2] = <&mut [u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(*bytes_head));
let bytes_tail: &mut [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(*bytes_tail));type Error = TryFromSliceError
§impl<'ber, 'a> TryFrom<Any<'ber>> for AlgorithmIdentifier<'a>where
'ber: 'a,
impl<'ber, 'a> TryFrom<Any<'ber>> for AlgorithmIdentifier<'a>where
'ber: 'a,
§impl<'trie, T> TryFrom<&'trie CodePointTrie<'trie, T>> for &'trie FastCodePointTrie<'trie, T>where
T: TrieValue,
impl<'trie, T> TryFrom<&'trie CodePointTrie<'trie, T>> for &'trie FastCodePointTrie<'trie, T>where
T: TrieValue,
§impl<'trie, T> TryFrom<&'trie CodePointTrie<'trie, T>> for &'trie SmallCodePointTrie<'trie, T>where
T: TrieValue,
impl<'trie, T> TryFrom<&'trie CodePointTrie<'trie, T>> for &'trie SmallCodePointTrie<'trie, T>where
T: TrieValue,
§impl<'trie, T> TryFrom<CodePointTrie<'trie, T>> for SmallCodePointTrie<'trie, T>where
T: TrieValue,
impl<'trie, T> TryFrom<CodePointTrie<'trie, T>> for SmallCodePointTrie<'trie, T>where
T: TrieValue,
§impl<B> TryFrom<&UnparsedPublicKey<B>> for ParsedPublicKey
impl<B> TryFrom<&UnparsedPublicKey<B>> for ParsedPublicKey
type Error = KeyRejected
§impl<B> TryFrom<UnparsedPublicKey<B>> for ParsedPublicKey
impl<B> TryFrom<UnparsedPublicKey<B>> for ParsedPublicKey
type Error = KeyRejected
Source§impl<N, E, Ix> TryFrom<Graph<N, E, Directed, Ix>> for Acyclic<Graph<N, E, Directed, Ix>>where
Ix: IndexType,
impl<N, E, Ix> TryFrom<Graph<N, E, Directed, Ix>> for Acyclic<Graph<N, E, Directed, Ix>>where
Ix: IndexType,
§impl<O, P> TryFrom<I32<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I32<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<I64<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I64<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<I64<P>> for I32<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I64<P>> for I32<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<I128<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I128<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<I128<P>> for I32<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I128<P>> for I32<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<I128<P>> for I64<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<I128<P>> for I64<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<Isize<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<Isize<P>> for I16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U32<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U32<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U64<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U64<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U64<P>> for U32<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U64<P>> for U32<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U128<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U128<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U128<P>> for U32<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U128<P>> for U32<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<U128<P>> for U64<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<U128<P>> for U64<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<O, P> TryFrom<Usize<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
impl<O, P> TryFrom<Usize<P>> for U16<O>where
O: ByteOrder,
P: ByteOrder,
type Error = TryFromIntError
§impl<S> TryFrom<RiReferenceString<S>> for RiAbsoluteString<S>where
S: Spec,
Available on crate feature alloc only.
impl<S> TryFrom<RiReferenceString<S>> for RiAbsoluteString<S>where
S: Spec,
alloc only.§impl<S> TryFrom<RiReferenceString<S>> for RiRelativeString<S>where
S: Spec,
Available on crate feature alloc only.
impl<S> TryFrom<RiReferenceString<S>> for RiRelativeString<S>where
S: Spec,
alloc only.§impl<S> TryFrom<RiReferenceString<S>> for RiString<S>where
S: Spec,
Available on crate feature alloc only.
impl<S> TryFrom<RiReferenceString<S>> for RiString<S>where
S: Spec,
alloc only.§impl<S> TryFrom<RiString<S>> for RiAbsoluteString<S>where
S: Spec,
Available on crate feature alloc only.
impl<S> TryFrom<RiString<S>> for RiAbsoluteString<S>where
S: Spec,
alloc only.§impl<S, C> TryFrom<Expanded<'_, S, C>> for RiAbsoluteString<S>where
S: Spec,
C: Context,
Available on crate feature alloc only.
impl<S, C> TryFrom<Expanded<'_, S, C>> for RiAbsoluteString<S>where
S: Spec,
C: Context,
alloc only.§impl<S, C> TryFrom<Expanded<'_, S, C>> for RiReferenceString<S>where
S: Spec,
C: Context,
Available on crate feature alloc only.
impl<S, C> TryFrom<Expanded<'_, S, C>> for RiReferenceString<S>where
S: Spec,
C: Context,
alloc only.§impl<S, C> TryFrom<Expanded<'_, S, C>> for RiRelativeString<S>where
S: Spec,
C: Context,
Available on crate feature alloc only.
impl<S, C> TryFrom<Expanded<'_, S, C>> for RiRelativeString<S>where
S: Spec,
C: Context,
alloc only.§impl<S, C> TryFrom<Expanded<'_, S, C>> for RiString<S>where
S: Spec,
C: Context,
Available on crate feature alloc only.
impl<S, C> TryFrom<Expanded<'_, S, C>> for RiString<S>where
S: Spec,
C: Context,
alloc only.§impl<T> TryFrom<Vec<T>> for NonEmptyVec<T>
impl<T> TryFrom<Vec<T>> for NonEmptyVec<T>
type Error = NonEmptyVecEmptyError
§impl<T> TryFrom<ExecuteScript> for Event<EventData<T>>
impl<T> TryFrom<ExecuteScript> for Event<EventData<T>>
type Error = EventBuildError
§impl<T> TryFrom<PatchElements> for Event<EventData<T>>
impl<T> TryFrom<PatchElements> for Event<EventData<T>>
type Error = EventBuildError
§impl<T> TryFrom<PatchSignals<T>> for Event<EventData<T>>
impl<T> TryFrom<PatchSignals<T>> for Event<EventData<T>>
type Error = EventBuildError
§impl<T> TryFrom<PatchSignals<T>> for Event<PatchSignals<T>>
impl<T> TryFrom<PatchSignals<T>> for Event<PatchSignals<T>>
type Error = EventBuildError
1.43.0 · Source§impl<T, A, const N: usize> TryFrom<Arc<[T], A>> for Arc<[T; N], A>where
A: Allocator,
impl<T, A, const N: usize> TryFrom<Arc<[T], A>> for Arc<[T; N], A>where
A: Allocator,
1.34.0 (const: unstable) · Source§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
type Error = Infallible
1.34.0 (const: unstable) · Source§impl<T, const N: usize> TryFrom<&[T]> for [T; N]where
T: Copy,
Tries to create an array [T; N] by copying from a slice &[T].
Succeeds if slice.len() == N.
impl<T, const N: usize> TryFrom<&[T]> for [T; N]where
T: Copy,
Tries to create an array [T; N] by copying from a slice &[T].
Succeeds if slice.len() == N.
let bytes: [u8; 3] = [1, 0, 2];
let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(bytes_head));
let bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(bytes_tail));type Error = TryFromSliceError
Source§impl<T, const N: usize> TryFrom<&[T]> for Simd<T, N>where
T: SimdElement,
impl<T, const N: usize> TryFrom<&[T]> for Simd<T, N>where
T: SimdElement,
type Error = TryFromSliceError
1.59.0 (const: unstable) · Source§impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]where
T: Copy,
Tries to create an array [T; N] by copying from a mutable slice &mut [T].
Succeeds if slice.len() == N.
impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]where
T: Copy,
Tries to create an array [T; N] by copying from a mutable slice &mut [T].
Succeeds if slice.len() == N.
let mut bytes: [u8; 3] = [1, 0, 2];
let bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap();
assert_eq!(1, u16::from_le_bytes(bytes_head));
let bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();
assert_eq!(512, u16::from_le_bytes(bytes_tail));type Error = TryFromSliceError
Source§impl<T, const N: usize> TryFrom<&mut [T]> for Simd<T, N>where
T: SimdElement,
impl<T, const N: usize> TryFrom<&mut [T]> for Simd<T, N>where
T: SimdElement,
type Error = TryFromSliceError
1.66.0 · Source§impl<T, const N: usize> TryFrom<Vec<T>> for rama::utils::collections::smallvec::alloc::boxed::Box<[T; N]>
Available on non-no_global_oom_handling only.
impl<T, const N: usize> TryFrom<Vec<T>> for rama::utils::collections::smallvec::alloc::boxed::Box<[T; N]>
no_global_oom_handling only.1.43.0 · Source§impl<T, const N: usize> TryFrom<Box<[T]>> for rama::utils::collections::smallvec::alloc::boxed::Box<[T; N]>
impl<T, const N: usize> TryFrom<Box<[T]>> for rama::utils::collections::smallvec::alloc::boxed::Box<[T; N]>
§impl<VE> TryFrom<&[u8]> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a byte slice to a MetadataValue.
impl<VE> TryFrom<&[u8]> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a byte slice to a MetadataValue.
For Ascii metadata values, If the argument contains invalid metadata value bytes, an error is returned. Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127 (DEL).
For Binary metadata values this method cannot fail. See also the Binary
only version of this method from_bytes.
type Error = InvalidMetadataValueBytes
§impl<VE> TryFrom<Bytes> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a Bytes buffer to a MetadataValue.
impl<VE> TryFrom<Bytes> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a Bytes buffer to a MetadataValue.
For MetadataValue<Ascii>, if the argument contains invalid metadata
value bytes, an error is returned. Only byte values between 32 and 255
(inclusive) are permitted, excluding byte 127 (DEL).
For MetadataValue<Binary>, if the argument is not valid base64, an
error is returned. In use cases where the input is not base64 encoded,
use from_bytes; if the value has to be encoded it’s not possible to
share the memory anyways.
type Error = InvalidMetadataValueBytes
§impl<VE> TryFrom<Vec<u8>> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a Vec of bytes to a MetadataValue.
impl<VE> TryFrom<Vec<u8>> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a Vec of bytes to a MetadataValue.
For MetadataValue<Ascii>, if the argument contains invalid metadata
value bytes, an error is returned. Only byte values between 32 and 255
(inclusive) are permitted, excluding byte 127 (DEL).
For MetadataValue<Binary>, if the argument is not valid base64, an
error is returned. In use cases where the input is not base64 encoded,
use from_bytes; if the value has to be encoded it’s not possible to
share the memory anyways.
type Error = InvalidMetadataValueBytes
§impl<VE, const N: usize> TryFrom<&[u8; N]> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a byte slice to a MetadataValue.
impl<VE, const N: usize> TryFrom<&[u8; N]> for MetadataValue<VE>where
VE: ValueEncoding,
Attempt to convert a byte slice to a MetadataValue.
For Ascii metadata values, If the argument contains invalid metadata value bytes, an error is returned. Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127 (DEL).
For Binary metadata values this method cannot fail. See also the Binary
only version of this method from_bytes.