pub trait Storable {
    fn to_bytes(&self) -> Cow<'_, [u8]>;
    fn from_bytes(bytes: Vec<u8>) -> Self;
}
Expand description

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

Required Methods

Converts an element into bytes.

NOTE: Cow is used here to avoid unnecessary cloning.

Converts bytes into an element.

NOTE: The bytes are passed as a Vec<u8> as opposed to &[u8] because in the vast majority of cases, the caller will no longer need the bytes, and passing a Vec<u8> prevents unnecessary cloning.

Implementations on Foreign Types

Implementors