Trait Serializable

Source
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]

Provided Associated Constants§

Source

const SIZE: usize = N

The size of

Required Associated Types§

Source

type Error

The type returned in the event of a conversion error.

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]].

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 Serializable<{ core::mem::size_of::<$ty>() }> for i8

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

type Error = Error

Source§

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

Source§

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

Implementors§