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;

    // 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. 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§

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 c_size_t?

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

source

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

Compares byte representation

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.

Implementations on Foreign Types§

source§

impl Storable for ()

Implementation for unit type to be used as key for databases inhabited by a single value only

source§

const CONST_BYTES_LEN: bool = true

source§

const TRIVIAL_CMP: bool = true

§

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

source§

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

source§

fn bytes_len(&self) -> usize

§

type AlignedRef<'a> = &'static ()

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 = 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 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 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 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 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 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 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 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 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 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 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 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<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 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 [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 [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 [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 = 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 [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 [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

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 [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 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 [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 = 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 [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 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<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<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

Implementors§