Trait ic_stable_structures::storable::Storable

source ·
pub trait Storable {
    const BOUND: Bound;

    // Required methods
    fn to_bytes(&self) -> Cow<'_, [u8]>;
    fn from_bytes(bytes: Cow<'_, [u8]>) -> Self;

    // Provided method
    fn to_bytes_checked(&self) -> Cow<'_, [u8]> { ... }
}
Expand description

A trait with convenience methods for storing an element into a stable structure.

Required Associated Constants§

source

const BOUND: Bound

The size bounds of the type.

Required Methods§

source

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

Converts an element into bytes.

NOTE: Cow is used here to avoid unnecessary cloning.

source

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

Converts bytes into an element.

Provided Methods§

source

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

Like to_bytes, but includes additional checks to ensure the element’s serialized bytes are within the element’s bounds.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Storable for bool

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for f32

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for f64

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for u8

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for u16

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for u32

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for u64

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for u128

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for ()

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl Storable for String

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = Bound::Unbounded

source§

impl Storable for Vec<u8>

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = Bound::Unbounded

source§

impl Storable for Principal

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl<A, B> Storable for (A, B)
where A: Storable, B: Storable,

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl<A, B, C> Storable for (A, B, C)
where A: Storable, B: Storable, C: Storable,

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl<T: Storable> Storable for Option<T>

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

source§

impl<T: Storable> Storable for Reverse<T>

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = T::BOUND

source§

impl<const N: usize> Storable for [u8; N]

source§

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

source§

fn from_bytes(bytes: Cow<'_, [u8]>) -> Self

source§

const BOUND: Bound = _

Implementors§

source§

impl<const N: usize> Storable for Blob<N>

source§

const BOUND: Bound = _