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§
Required Methods§
sourcefn to_bytes(&self) -> Cow<'_, [u8]>
fn to_bytes(&self) -> Cow<'_, [u8]>
Converts an element into bytes.
NOTE: Cow
is used here to avoid unnecessary cloning.
sourcefn from_bytes(bytes: Cow<'_, [u8]>) -> Self
fn from_bytes(bytes: Cow<'_, [u8]>) -> Self
Converts bytes into an element.
Provided Methods§
sourcefn to_bytes_checked(&self) -> Cow<'_, [u8]>
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.