pub trait Serializable<const N: usize> {
    type Error;

    const SIZE: usize = N;

    // Required methods
    fn from_bytes(buf: &[u8; N]) -> Result<Self, Self::Error>
       where Self: Sized;
    fn to_bytes(&self) -> [u8; N];
}
Expand description

The core trait used to implement [from_bytes] and [to_bytes]

Required Associated Types§

source

type Error

The type returned in the event of a conversion error.

Provided Associated Constants§

source

const SIZE: usize = N

The size of

Required Methods§

source

fn from_bytes(buf: &[u8; N]) -> Result<Self, Self::Error>
where Self: Sized,

Deserialize a [&[u8; N]] into Self, it might be fail.

source

fn to_bytes(&self) -> [u8; N]

Serialize Self into a [[u8; N]].

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for i8

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 1]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 1]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for i16

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 2]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 2]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for i32

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 4]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 4]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for i64

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 8]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 8]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for i128

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 16]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 16]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for u8

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 1]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 1]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for u16

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 2]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 2]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for u32

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 4]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 4]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for u64

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 8]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 8]

source§

impl Serializable<{ core::mem::size_of::<$ty>() }> for u128

§

type Error = Error

source§

fn from_bytes(buf: &[u8; 16]) -> Result<Self, Self::Error>

source§

fn to_bytes(&self) -> [u8; 16]

Implementors§