Trait lmdb_zero::traits::LmdbOrdKey [] [src]

pub unsafe trait LmdbOrdKey: FromLmdbBytes + Ord {
    fn ordered_by_bytes() -> bool { ... }
    fn ordered_as_integer() -> bool { ... }
}

Trait describing a value which can be used as an LMDB key by having LMDB call into the value's Ord implementation.

Unsafety

Behaviour is undefined if the FromLmdbBytes or Ord implementations panic.

Provided Methods

fn ordered_by_bytes() -> bool

Returns whether the default LMDB byte-by-byte comparison is correct for valid values of this type.

Generally, one should not specifically use DatabaseOptions::sort_values_as and so forth for types where this is the case. This function exists to support generic code wishing to avoid the conversion overhead when the types happen to already be byte-comparable.

Note that if this returns true, that does not mean that byte comparison is exactly equivalent to Ord-based comparison. For example, invalid str instances sort before valid ones and are equal to each other, but byte comparison will intermingle them. Because of this, DatabaseOptions::sort_values_as and similar do not make decisions based on this value; it is the client code's responsibility to use this if so desired.

Example

assert!(<u8 as LmdbOrdKey>::ordered_by_bytes());
assert!(!<i8 as LmdbOrdKey>::ordered_by_bytes());
assert!(<str as LmdbOrdKey>::ordered_by_bytes());
assert!(<[u8] as LmdbOrdKey>::ordered_by_bytes());
assert!(!<[i8] as LmdbOrdKey>::ordered_by_bytes());

fn ordered_as_integer() -> bool

Returns whether LMDB will correctly handle this value with the INTEGERKEY or INTEGERDUP flags.

There's generally no reason to use sort_keys_as and so forth with values where this is true instead of using the appropriate flags. This function exists to support generic code which wants to make such decisions automatically.

Implementors