2 releases
Uses old Rust 2015
0.1.1 | Apr 25, 2018 |
---|---|
0.1.0 | Apr 25, 2018 |
#12 in #foundation-db
36KB
872 lines
Binary Tuples
This is a small library for working with ordered binary tuples - and is designed to be compatible with the tuples implementation bundled with FoundationDB client libraries.
This library allows use of the following data types:
- Strings
- Binary arrays
- Numbers (
i64
,f32
,f64
) - Boolean values
- UUIDs
- Nested tuples (read supported - no api support for creation yet)
API
The easiest way to create tuples is using the exposed tuple!
macro:
#[macro_use]
extern crate binary_tuples;
let user_id = 1;
let value = tuple!("users", user_id, "posts");
// Returns as a byte array
let bytes = value.into_bytes();
Tuples can also be deserialised into a vector of tuple segments:
use binary_tuples::{Tuple, segment::Segment};
let tuple = Tuple::from_bytes(...)
.as_segments()
.unwrap();
match tuple[0] {
Segment::String(value) => println!("{}", value),
_ => println!("Other data type")
}
Tuples can reused as efficient prefixes for other tuples
let users_tuple = tuple!("users", user_id, "posts");
let post_1 = tuple!(users_tuple, post_id_1);
let post_2 = tuple!(users_tuple, post_id_2);
Dependencies
~1MB
~12K SLoC