pub trait Storable: Sized + Copy {
// Required methods
fn to_word(self) -> u64;
fn from_word(word: u64) -> Self;
}
Expand description
A trait for types that can be stored in a variable-length compressed vector.
This trait provides a bidirectional, lossless conversion between a user-facing
element type (e.g., i32
, u16
) and the u64
representation required by the
underlying compression codecs.
§Zig-Zag Encoding for Signed Integers
For signed integer types, this trait’s implementation automatically applies Zig-Zag encoding. This is a transformation that maps signed integers to unsigned integers in a way that is efficient for variable-length compression.
It works by mapping small positive and negative numbers to small unsigned numbers, as shown below:
Original Signed | Zig-Zag Unsigned |
---|---|
0 | 0 |
-1 | 1 |
1 | 2 |
-2 | 3 |
2 | 4 |
… | … |
This ensures that values close to zero, whether positive or negative, are represented by small unsigned integers, which can then be compressed into very few bits by the variable-length codecs.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.