pub unsafe trait Storable: ToOwned {
    type BytesRef<'a>: GenericCow<Borrowed = [u8]>
        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
        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

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.

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

Does byte representation have fixed length?

If this constant is true, then trait StorableConstBytesLen should also be implemented.

Provided Associated Constants

Does Storable::cmp_bytes_unchecked perform a trivial (byte wise) lexicographical comparison?

Is type equivalent to c_uint or c_size_t?

Required Methods

Converts to byte slice

Converts from byte slice

Compares byte representation

Provided Methods

Length of byte representation

Compares byte representation using Ord

This function is provided for convenient implementation of Storable::cmp_bytes_unchecked where desired.

Implementations on Foreign Types