binn_rs/lib.rs
1//! Binn format with Rust
2//!
3//! binn-rs features no_alloc support and aims to provide better
4//! performance for embedded devices by using static allocations and
5//! providing zero-copy read operations
6//!
7//! # Quick start
8//!
9//! ```
10//! use binn_rs::{Object, Value};
11//!
12//! let mut buf = [0; 32];
13//! // create new object, that will use `buf` for storage
14//! // obj will have same lifetime as it's storage
15//! let mut obj = Object::empty_mut(buf.as_mut_slice()).unwrap();
16//!
17//! // add some values
18//! obj.add_value("key1", Value::False).unwrap();
19//! obj.add_value("key2", Value::UInt16(6262)).unwrap();
20//!
21//! // get serialized representation
22//! let serialized = obj.as_bytes();
23//!
24//! let expected = &[
25//! 0xE2, // [type] object (container)
26//! 0x11, // [size] container total size
27//! 0x02, // [count] key/value pairs
28//!
29//! 0x04, b'k', b'e', b'y', b'1', // key
30//! 0x02, // [type] = false
31//!
32//! 0x04, b'k', b'e', b'y', b'2', // key
33//! 0x40, // [type] = uint16
34//! 0x18, 0x76 // [data] (6262)
35//! ];
36//!
37//! assert_eq!(serialized, expected);
38//!
39//! // deserialize binn Value
40//! let value: Value = serialized.try_into().unwrap();
41//! // unwrap Object from value
42//! let obj: Object = value.try_into().unwrap();
43//!
44//! // check object contents
45//! let expected = vec![
46//! ("key1", Value::False),
47//! ("key2", Value::UInt16(6262)),
48//! ];
49//!
50//! assert_eq!(expected.len(), obj.count());
51//!
52//! for ((ref actual_key, ref actual_val), (expected_key, expected_val)) in
53//! obj.iter().zip(expected.iter())
54//! {
55//! assert_eq!(actual_key, expected_key);
56//! assert_eq!(actual_val, expected_val);
57//! }
58//!
59//! ```
60//!
61#![no_std]
62#![warn(rust_2018_idioms, missing_debug_implementations, missing_docs)]
63
64mod allocation;
65mod container;
66mod data_type;
67mod error;
68mod raw_container;
69mod size;
70mod storage;
71mod subtype;
72mod utils;
73mod value;
74
75pub use allocation::Allocation;
76pub use container::{List, Map, Object};
77pub use error::Error;
78pub use subtype::SubType;
79pub use value::Value;