TryFromByteArray

Trait TryFromByteArray 

Source
pub trait TryFromByteArray: AssociatedByteArray + Sized {
    type Error;

    // Required method
    fn try_from_byte_array(
        byte_array: Self::ByteArray,
    ) -> Result<Self, Self::Error>;
}
Expand description

Attempts to construct a value from its byte array representation, potentially failing.

This trait provides fallible construction from byte arrays, useful for types that may need validation or have constraints on valid byte patterns. Types that implement FromByteArray automatically implement this trait with Error = Infallible.

§Examples

use byteable::{FromByteArray, TryFromByteArray};

// Types that implement FromByteArray automatically get TryFromByteArray
let bytes = [42, 0, 0, 0];
let value = u32::try_from_byte_array(bytes).unwrap();
assert_eq!(value, u32::from_byte_array(bytes));

Required Associated Types§

Source

type Error

The type returned in the event of a conversion error.

Required Methods§

Source

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

Attempts to construct a value from its byte array representation.

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

Implementors§