pub unsafe trait Storable: Ord {
    type AlignedRef<'a>: Deref<Target = Self> + IntoOwned;
    type BytesRef<'a>: Deref<Target = [u8]>
    where
        Self: 'a
; const CONST_BYTES_LEN: bool; const OPTIMIZE_INT: bool = false; const TRIVIAL_CMP: bool = false; fn to_bytes(&self) -> Self::BytesRef<'_>; unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>; fn bytes_len(&self) -> usize { ... } unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering { ... } }
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.

The generic associated type AlignedRef is an ordinary shared reference or a smart-pointer holding a copy for the purpose of memory alignment. The generic associated type BytesRef is usually &[u8] (where bytes can be read directly from memory) or Vec<u8> (where bytes need to be copied).

Several constants must be set correctly to enable various optimizations.

Required Associated Types

Pointer to aligned version of Self

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> or Vec) which drops the re-aligned copy when the smart-pointer is dropped.

Pointer to byte representation

Required Associated Constants

Does byte representation have fixed length?

Provided Associated Constants

Is type equivalent to c_uint or c_size_t?

Is Ord consistent with lexicographical sorting of binary representation?

Required Methods

Converts to byte slice

Converts from byte slice

Provided Methods

Length of byte representation

Compares byte representation

Implementations on Foreign Types

Implementors