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§
Required Methods§
Sourcefn to_bytes(&self) -> Cow<'_, [u8]>
fn to_bytes(&self) -> Cow<'_, [u8]>
Converts the element into a possibly borrowed byte slice.
NOTE: Cow is used here to avoid unnecessary cloning.
Sourcefn into_bytes(self) -> Vec<u8> ⓘ
fn into_bytes(self) -> Vec<u8> ⓘ
Converts the element into an owned byte vector.
This method consumes self and avoids cloning when possible.
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 checks that bytes conform to declared bounds.
Sourcefn into_bytes_checked(self) -> Vec<u8> ⓘwhere
Self: Sized,
fn into_bytes_checked(self) -> Vec<u8> ⓘwhere
Self: Sized,
Like into_bytes, but checks that bytes conform to declared bounds.
Sourcefn check_bounds(bytes: &[u8])
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".