Serializable

Trait Serializable 

Source
pub trait Serializable {
    const IS_FIXED_SIZE: bool;

    // Required methods
    fn serialize(&self) -> Cow<'_, [u8]>;
    fn serialize_fixed_size(&self) -> Option<[u8; 8]>;
}
Expand description

Trait for serializing a type to a byte slice or a fixed size byte array.

Required Associated Constants§

Required Methods§

Source

fn serialize(&self) -> Cow<'_, [u8]>

May return a borrowed slice or an owned vector.

Source

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

May return None if the type is not fixed size representable.

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 for i8

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for i16

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for i32

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for i64

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for str

Source§

const IS_FIXED_SIZE: bool = false

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for u8

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for u16

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for u32

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for u64

Source§

const IS_FIXED_SIZE: bool = true

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for String

Source§

const IS_FIXED_SIZE: bool = false

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Source§

impl Serializable for Vec<u8>

Source§

const IS_FIXED_SIZE: bool = false

Source§

fn serialize(&self) -> Cow<'_, [u8]>

Source§

fn serialize_fixed_size(&self) -> Option<[u8; 8]>

Implementors§