pub unsafe trait Storable: ToOwned {
type BytesRef<'a>: GenericCow<Borrowed = [u8]>
where
Self: 'a;
type AlignedRef<'a>: GenericCow<Borrowed = Self>;
const CONST_BYTES_LEN: bool;
const TRIVIAL_CMP: bool = false;
const OPTIMIZE_INT: bool = false;
fn to_bytes(&self) -> Self::BytesRef<'_>;
unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>;
unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering;
fn bytes_len(&self) -> usize { ... }
unsafe fn cmp_bytes_by_ord_unchecked(a: &[u8], b: &[u8]) -> Ordering
where
Self: Ord,
{ ... }
}
Expand description
Types that can be stored
Any type that implements Storable
can be used as a key or value in a
Db
.
Implementation is unsafe
and must be correct and not change between
(re-)opening environments.
Types that have a fixed-length byte representation should additionally
implement StorableConstBytesLen
.
Several constants must be set correctly to enable various optimizations.
Required Associated Types§
sourcetype BytesRef<'a>: GenericCow<Borrowed = [u8]>
where
Self: 'a
type BytesRef<'a>: GenericCow<Borrowed = [u8]>
where
Self: 'a
Byte representation as GenericCow
This can be a simple reference (&'a Self
) or a
a smart-pointer (like Owned<[u8]>
) which drops the byte
representation when the smart-pointer is dropped.
sourcetype AlignedRef<'a>: GenericCow<Borrowed = Self>
type AlignedRef<'a>: GenericCow<Borrowed = Self>
Aligned version of Self
as GenericCow
This can be a simple reference (&'a Self
) if there
are no requirements for memory alignment, or can be a smart-pointer
(like Owned<Self>
) which drops the re-aligned copy when the
smart-pointer is dropped.
Required Associated Constants§
sourceconst CONST_BYTES_LEN: bool
const CONST_BYTES_LEN: bool
Does byte representation have fixed length?
If this constant is true
, then trait StorableConstBytesLen
should
also be implemented.
Provided Associated Constants§
sourceconst TRIVIAL_CMP: bool = false
const TRIVIAL_CMP: bool = false
Does Storable::cmp_bytes_unchecked
perform a trivial (byte wise)
lexicographical comparison?
sourceconst OPTIMIZE_INT: bool = false
const OPTIMIZE_INT: bool = false
Required Methods§
sourceunsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>
unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>
Converts from byte slice
sourceunsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering
unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering
Compares byte representation
Provided Methods§
sourceunsafe fn cmp_bytes_by_ord_unchecked(a: &[u8], b: &[u8]) -> Orderingwhere
Self: Ord,
unsafe fn cmp_bytes_by_ord_unchecked(a: &[u8], b: &[u8]) -> Orderingwhere
Self: Ord,
Compares byte representation using Ord
This function is provided for convenient implementation of
Storable::cmp_bytes_unchecked
where desired.