Crate memcomparable

Source
Expand description

A memcomparable serialization format.

The memcomparable format allows comparison of two values by using the simple memcmp function.

§Usage

// serialize
let key1 = memcomparable::to_vec(&"hello").unwrap();
let key2 = memcomparable::to_vec(&"world").unwrap();
assert!(key1 < key2);

// deserialize
let v1: String = memcomparable::from_slice(&key1).unwrap();
let v2: String = memcomparable::from_slice(&key2).unwrap();
assert_eq!(v1, "hello");
assert_eq!(v2, "world");

§Features

§Format

The serialization format follows MySQL’s memcomparable format.

TypeLength (bytes)
bool1
char4
i8/i16/i32/i64/u8/u16/u32/u641/2/4/8
f32/f644/8
DecimalVariable
str/bytes(L + 7) / 8 x 9
Option<T>1 + len(T)
&[T](1 + len(T)) x L + 1
(T1, T2, ..)sum(len(Ti))
struct { a: T1, b: T2, .. }sum(len(Ti))
enum { V1, V2, .. }1 + len(Vi)

WARN: The format is not guaranteed to be stable in minor version change, e.g. 0.1 -> 0.2.

Structs§

Deserializer
A structure that deserializes memcomparable bytes into Rust values.
Serializer
A structure for serializing Rust values into a memcomparable bytes.

Enums§

Decimal
An extended decimal number with NaN, -Inf and Inf.
Error
An error that can be produced during (de)serializing.

Functions§

from_slice
Deserialize an instance of type T from a memcomparable bytes.
to_vec
Serialize the given data structure as a memcomparable byte vector.

Type Aliases§

Result
The result of a serialization or deserialization operation.