dcbor/lib.rs
1#![doc(html_root_url = "https://docs.rs/dcbor/0.25.0")]
2#![warn(rust_2018_idioms)]
3#![cfg_attr(not(feature = "std"), no_std)]
4
5//! # dCBOR: Deterministic CBOR Codec
6//!
7//! `dcbor` is a reference implementation of Deterministic CBOR. The current
8//! specification of the norms and practices guiding the creation of this
9//! implementation are currently found in this IETF Internet Draft:
10//! [draft-mcnally-deterministic-cbor](https://datatracker.ietf.org/doc/draft-mcnally-deterministic-cbor/).
11//!
12//! # Getting Started
13//!
14//! Add the following to your `Cargo.toml`:
15//!
16//! ```toml
17//! [dependencies]
18//! dcbor = "0.25.0"
19//! ```
20//!
21//! # Features
22//!
23//! ## Multi-threaded
24//!
25//! The `multithreaded` feature is available but not enabled by default. It uses
26//! `Arc` for reference counting instead of `Rc`. To enable it, add the
27//! following to your `Cargo.toml`:
28//!
29//! ```toml
30//! [dependencies.dcbor]
31//! version = "0.25.0"
32//! features = ["multithreaded"]
33//! ```
34//!
35//! ## `no_std`
36//!
37//! The `dcbor` library is `no_std` compatible. To use it in a `no_std`
38//! environment, disable the default features in your `Cargo.toml` and enable
39//! the `no_std` feature:
40//!
41//! ```toml
42//! [dependencies.dcbor]
43//! version = "0.25.0"
44//! default-features = false
45//! features = ["no_std"]
46//! ```
47//!
48//! # Usage
49//!
50//! Encode an array of integers as CBOR.
51//!
52//! ```
53//! # fn main() {
54//! # {
55//! use dcbor::prelude::*;
56//! let array = [1000, 2000, 3000];
57//! let cbor: CBOR = array.into();
58//! assert_eq!(cbor.hex(), "831903e81907d0190bb8");
59//! # }
60//! # }
61//! ```
62//!
63//! Decode CBOR binary back to an array of integers.
64//!
65//! ```
66//! # fn main() {
67//! # {
68//! use dcbor::prelude::*;
69//! let data = hex_literal::hex!("831903e81907d0190bb8");
70//! let cbor = CBOR::try_from_data(&data).unwrap();
71//! assert_eq!(cbor.diagnostic(), "[1000, 2000, 3000]");
72//! let array: Vec<u32> = cbor.try_into().unwrap();
73//! assert_eq!(format!("{:?}", array), "[1000, 2000, 3000]");
74//! # }
75//! # }
76//! ```
77//!
78//! See the unit tests For further examples, including encoding and decoding
79//! arrays with heterogenous elements, maps, and user-defined types with custom
80//! CBOR tags.
81
82#[macro_use]
83mod stdlib;
84
85mod cbor;
86pub use cbor::*;
87
88mod byte_string;
89pub use byte_string::ByteString;
90
91mod bool_value;
92
93mod float;
94
95mod array;
96pub use array::CBORSortable;
97
98mod error;
99pub use error::{Error, Result};
100
101mod date;
102pub use date::Date;
103
104mod diag;
105pub use diag::DiagFormatOpts;
106mod dump;
107pub use dump::HexFormatOpts;
108
109mod tags_store;
110pub use tags_store::{CBORSummarizer, TagsStore, TagsStoreOpt, TagsStoreTrait};
111
112mod tag;
113pub use tag::{Tag, TagValue};
114
115mod tags;
116pub use tags::*;
117
118mod cbor_codable;
119pub use cbor_codable::{CBORCodable, CBORDecodable, CBOREncodable};
120
121mod cbor_tagged;
122pub use cbor_tagged::CBORTagged;
123
124mod cbor_tagged_encodable;
125pub use cbor_tagged_encodable::CBORTaggedEncodable;
126mod cbor_tagged_decodable;
127pub use cbor_tagged_decodable::CBORTaggedDecodable;
128mod cbor_tagged_codable;
129pub use cbor_tagged_codable::CBORTaggedCodable;
130
131mod decode;
132
133mod int;
134
135mod map;
136pub use map::{Map, MapIter};
137
138mod set;
139pub use set::{Set, SetIter};
140
141mod string;
142
143mod string_util;
144
145mod simple;
146pub use simple::Simple;
147
148mod exact;
149mod varint;
150use exact::ExactFrom;
151
152#[cfg(feature = "num-bigint")]
153mod num_bigint;
154#[cfg(feature = "num-bigint")]
155pub use num_bigint::{
156 BigInt, BigUint, Sign, bigint_from_negative_untagged_cbor,
157 biguint_from_untagged_cbor,
158};
159
160pub mod walk;
161
162pub mod prelude;
163
164mod conveniences;
165
166// Re-export standard library types used in our public API
167#[doc(hidden)]
168pub use stdlib::public_exports::*;