pinecone/
lib.rs

1//! Pinecone, a minimalistic `no_std` + `alloc` serde format
2//!
3//! Works just like any other normal serde:
4//!
5//! ```rust
6//! use pinecone::{from_bytes, to_slice, to_vec};
7//! use serde::{Deserialize, Serialize};
8//!
9//! #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
10//! struct Example {
11//!     foo: String,
12//!     bar: Option<u32>,
13//!     zot: bool,
14//! }
15//!
16//! let original = Example {
17//!     foo: "Vec test".to_string(),
18//!     bar: Some(0x1337),
19//!     zot: true,
20//! };
21//!
22//! let bytes: Vec<u8> = to_vec(&original).expect("Serialization failed");
23//! assert_eq!(from_bytes(&bytes), Ok(original));
24//!
25//! let original = Example {
26//!     foo: "Slice test".to_string(),
27//!     bar: Some(0x1337),
28//!     zot: true,
29//! };
30//!
31//! let mut buffer = [0; 1024];
32//! to_slice(&original, &mut buffer).expect("Serialization failed");
33//! assert_eq!(from_bytes(&buffer), Ok(original));
34//! ```
35
36#![cfg_attr(not(feature = "use-std"), no_std)]
37// #![deny(missing_docs)]
38#![allow(unused_imports)]
39
40// #[cfg(all(test, not(feature = "use-std")))]
41// compile_error!("Trying to run tests without std. Supply --features use-std to run.");
42
43#[cfg(not(feature = "use-std"))]
44extern crate alloc;
45
46#[cfg(not(feature = "use-std"))]
47mod prelude {
48    pub use alloc::format;
49    pub use alloc::{string::String, vec::Vec};
50    #[cfg(test)]
51    pub use hashbrown::HashMap;
52}
53
54#[cfg(feature = "use-std")]
55mod prelude {
56    #[cfg(test)]
57    pub use std::collections::HashMap;
58}
59
60mod de;
61mod error;
62mod ser;
63mod varint;
64
65pub use de::deserializer::Deserializer;
66pub use de::{from_bytes, take_from_bytes};
67pub use error::{Error, Result};
68pub use ser::{serializer::Serializer, to_slice, to_vec};