Byteable

Trait Byteable 

Source
pub trait Byteable: Copy {
    type ByteArray: ByteableByteArray;

    const BINARY_SIZE: usize = <Self::ByteArray>::BINARY_SIZE;

    // Required methods
    fn as_bytearray(self) -> Self::ByteArray;
    fn from_bytearray(ba: Self::ByteArray) -> Self;
}
Expand description

Trait for types that can be converted to and from a byte array.

This trait is central to the byteable crate, enabling structured data to be easily serialized into and deserialized from byte arrays.

Provided Associated Constants§

Source

const BINARY_SIZE: usize = <Self::ByteArray>::BINARY_SIZE

Required Associated Types§

Source

type ByteArray: ByteableByteArray

The associated byte array type that can represent Self.

Required Methods§

Source

fn as_bytearray(self) -> Self::ByteArray

Converts self into its ByteableByteArray representation.

Source

fn from_bytearray(ba: Self::ByteArray) -> Self

Creates an instance of Self from a ByteableByteArray.

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 Byteable for f32

Source§

type ByteArray = [u8; 4]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for f64

Source§

type ByteArray = [u8; 8]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for i8

Source§

type ByteArray = [u8; 1]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for i16

Source§

type ByteArray = [u8; 2]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for i32

Source§

type ByteArray = [u8; 4]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for i64

Source§

type ByteArray = [u8; 8]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for i128

Source§

type ByteArray = [u8; 16]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for u8

Source§

type ByteArray = [u8; 1]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for u16

Source§

type ByteArray = [u8; 2]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for u32

Source§

type ByteArray = [u8; 4]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for u64

Source§

type ByteArray = [u8; 8]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Source§

impl Byteable for u128

Source§

type ByteArray = [u8; 16]

Source§

fn as_bytearray(self) -> Self::ByteArray

Source§

fn from_bytearray(ba: Self::ByteArray) -> Self

Implementors§

Source§

impl<Raw, Regular> Byteable for Regular
where Regular: ByteableRegular<Raw = Raw> + Copy, Raw: Byteable,

Source§

impl<T: Endianable> Byteable for BigEndian<T>

Source§

impl<T: Endianable> Byteable for LittleEndian<T>