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§
Required Methods§
Sourcefn try_from_byte_array(byte_array: Self::ByteArray) -> Result<Self, Self::Error>
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.