Skip to main content

TryFromByteArray

Trait TryFromByteArray 

Source
pub trait TryFromByteArray: IntoByteArray {
    // Required method
    fn try_from_byte_array(
        byte_array: Self::ByteArray,
    ) -> Result<Self, DecodeError>;
}
Expand description

Fallible conversion from a fixed-size byte array back into a value.

Use this when decoding can fail (e.g. bool, char, NonZero<T>). Returns DecodeError on failure.

For types that implement FromByteArray, a blanket impl provides TryFromByteArray automatically by wrapping the infallible conversion in Ok(...).

§Errors

Returns DecodeError if the byte array does not represent a valid value of Self.

Required Methods§

Source

fn try_from_byte_array(byte_array: Self::ByteArray) -> Result<Self, DecodeError>

Attempt to deserialize a value from a fixed-size byte array.

§Errors

Returns DecodeError if the bytes are not a valid encoding of Self.

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.

Implementations on Foreign Types§

Source§

impl TryFromByteArray for bool

Source§

impl TryFromByteArray for char

Source§

impl TryFromByteArray for NonZero<i8>

Source§

impl TryFromByteArray for NonZero<i16>

Source§

impl TryFromByteArray for NonZero<i32>

Source§

impl TryFromByteArray for NonZero<i64>

Source§

impl TryFromByteArray for NonZero<i128>

Source§

impl TryFromByteArray for NonZero<u8>

Source§

impl TryFromByteArray for NonZero<u16>

Source§

impl TryFromByteArray for NonZero<u32>

Source§

impl TryFromByteArray for NonZero<u64>

Source§

impl TryFromByteArray for NonZero<u128>

Implementors§