Storable

Trait Storable 

Source
pub trait Storable {
    const BOUND: Bound;

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

    // Provided methods
    fn to_bytes_checked(&self) -> Cow<'_, [u8]> { ... }
    fn into_bytes_checked(self) -> Vec<u8> 
       where Self: Sized { ... }
    fn check_bounds(bytes: &[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 the element into a possibly borrowed byte slice.

NOTE: Cow is used here to avoid unnecessary cloning.

Source

fn into_bytes(self) -> Vec<u8>

Converts the element into an owned byte vector.

This method consumes self and avoids cloning when possible.

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 checks that bytes conform to declared bounds.

Source

fn into_bytes_checked(self) -> Vec<u8>
where Self: Sized,

Like into_bytes, but checks that bytes conform to declared bounds.

Source

fn check_bounds(bytes: &[u8])

Validates that a byte slice fits within this type’s declared bounds.

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 Storable for bool

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for f32

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for f64

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for u8

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for u16

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for u32

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for u64

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for u128

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for ()

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for String

Source§

const BOUND: Bound = Bound::Unbounded

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for Vec<u8>

Source§

const BOUND: Bound = Bound::Unbounded

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

impl Storable for Principal

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

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

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

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

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

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

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

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

Source§

const BOUND: Bound = T::BOUND

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Source§

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

Source§

const BOUND: Bound

Source§

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

Source§

fn into_bytes(self) -> Vec<u8>

Source§

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

Implementors§

Source§

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

Source§

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

Source§

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

Source§

const BOUND: Bound = Bound::Unbounded