pub trait IntoByteArray: Sized {
type ByteArray: ByteArray;
const BYTE_SIZE: usize = <Self::ByteArray>::BYTE_SIZE;
// Required method
fn into_byte_array(&self) -> Self::ByteArray;
}Expand description
Conversion from a value into its fixed-size byte representation.
Implementing this trait (together with TryFromByteArray or FromByteArray) enables
zero-copy, allocation-free serialization for types whose wire size is known at compile time.
BYTE_SIZE is a compile-time constant equal to the number of
bytes produced by into_byte_array.
§Examples
use byteable::{Byteable, IntoByteArray};
#[derive(Byteable)]
struct Pair {
a: u16,
b: u16,
}
let p = Pair { a: 1, b: 2 };
assert_eq!(Pair::BYTE_SIZE, 4);
let bytes: [u8; 4] = p.into_byte_array();Provided Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn into_byte_array(&self) -> Self::ByteArray
fn into_byte_array(&self) -> Self::ByteArray
Serialize this value into a fixed-size byte array.
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.