pub unsafe trait Storable {
    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;

    // Required methods
    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;

    // Provided methods
    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. Types that have a fixed-length byte representation should additionally implement StorableConstBytesLen. Several constants must be set correctly to enable various optimizations.

Safety

  • CONST_BYTES_LEN must only be true if to_bytes always returns a pointer to a byte slice with the same length.
  • TRIVIAL_CMP must only be true if cmp_bytes_unchecked, when receiving two arguments which have been returned by the to_bytes method of the same type, performs a lexicographical comparison of those two byte slices.
  • OPTIMIZE_INT must only be true if the type is equivalent to c_uint or the C type size_t and the byte representation is in native byte order.
  • to_bytes must return a byte representation that can be safely passed to from_bytes_unchecked (of the same type).
  • cmp_bytes_unchecked must be stable, i.e. always return the same result for the same input (for the same type).
  • cmp_bytes_unchecked must never unwind.

Required Associated Types§

source

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.

source

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§

source

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§

source

const TRIVIAL_CMP: bool = false

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

source

const OPTIMIZE_INT: bool = false

Is type equivalent to c_uint or the C type size_t, and is its byte representation in native byte order?

Required Methods§

source

fn to_bytes(&self) -> Self::BytesRef<'_>

Converts to byte slice

source

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

Converts from byte slice

Safety

The passed byte representation (bytes) must have been created with <Self as Storable>::to_bytes on the same platform (same endianess / word size).

source

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

Compares byte representation

Safety

The passed byte representations (a and b) must have been created with <Self as Storable>::to_bytes on the same platform (same endianess / word size).

Provided Methods§

source

fn bytes_len(&self) -> usize

Length of byte representation

source

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.

Safety

The passed byte representations (a and b) must have been created with <Self as Storable>::to_bytes on the same platform (same endianess / word size).

Implementations on Foreign Types§

source§

impl Storable for [usize]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[usize]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [u16]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[u16]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for u32

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<u32>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for i128

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<i128>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [u64]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[u64]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for str

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = &'a str

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [isize]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[isize]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl<T1, T2> Storable for (T1, T2)where T1: Clone + BorrowStorable, T2: Clone + BorrowStorable, <T1 as BorrowStorable>::Stored: StorableConstBytesLen,

source§

const CONST_BYTES_LEN: bool = <<T2 as BorrowStorable>::Stored>::CONST_BYTES_LEN

source§

const TRIVIAL_CMP: bool = _

§

type AlignedRef<'a> = Owned<(T1, T2)>

§

type BytesRef<'a> where Self: 'a = Owned<[u8]>

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for u64

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<u64>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl<T1, T2, T3, T4> Storable for (T1, T2, T3, T4)where T1: Clone + BorrowStorable, T2: Clone + BorrowStorable, T3: Clone + BorrowStorable, T4: Clone + BorrowStorable, <T1 as BorrowStorable>::Stored: StorableConstBytesLen, <T2 as BorrowStorable>::Stored: StorableConstBytesLen, <T3 as BorrowStorable>::Stored: StorableConstBytesLen,

source§

const CONST_BYTES_LEN: bool = <<T4 as BorrowStorable>::Stored>::CONST_BYTES_LEN

source§

const TRIVIAL_CMP: bool = _

§

type AlignedRef<'a> = Owned<(T1, T2, T3, T4)>

§

type BytesRef<'a> where Self: 'a = Owned<[u8]>

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for u128

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<u128>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [i128]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[i128]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl<T1, T2, T3> Storable for (T1, T2, T3)where T1: Clone + BorrowStorable, T2: Clone + BorrowStorable, T3: Clone + BorrowStorable, <T1 as BorrowStorable>::Stored: StorableConstBytesLen, <T2 as BorrowStorable>::Stored: StorableConstBytesLen,

source§

const CONST_BYTES_LEN: bool = <<T3 as BorrowStorable>::Stored>::CONST_BYTES_LEN

source§

const TRIVIAL_CMP: bool = _

§

type AlignedRef<'a> = Owned<(T1, T2, T3)>

§

type BytesRef<'a> where Self: 'a = Owned<[u8]>

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [i8]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = &'a [i8]

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl<const N: usize> Storable for [u8; N]

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = &'a [u8; N]

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [i64]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[i64]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [u32]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[u32]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for i32

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<i32>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for i8

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = &'a i8

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for u16

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<u16>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for u8

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = &'a u8

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [i32]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[i32]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for i64

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<i64>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for usize

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<usize>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [bool]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = &'a [bool]

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for i16

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<i16>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [i16]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[i16]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for isize

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = false

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = Owned<isize>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for bool

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

source§

const OPTIMIZE_INT: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = &'a bool

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [u8]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = true

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = &'a [u8]

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

source§

impl Storable for [u128]

source§

const CONST_BYTES_LEN: bool = false

source§

const TRIVIAL_CMP: bool = false

§

type BytesRef<'a> = &'a [u8]

source§

fn to_bytes(&self) -> Self::BytesRef<'_>

§

type AlignedRef<'a> = Owned<[u128]>

source§

unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self::AlignedRef<'_>

source§

unsafe fn cmp_bytes_unchecked(a: &[u8], b: &[u8]) -> Ordering

Implementors§

source§

impl Storable for NoKey

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

§

type BytesRef<'a> = &'static [u8]

§

type AlignedRef<'a> = &'static NoKey

source§

impl Storable for NoValue

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

§

type BytesRef<'a> = &'static [u8]

§

type AlignedRef<'a> = &'static NoValue