1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Make a non-self-describing [`serde`](https://docs.rs/serde) format (like
//! [`bincode`](https://docs.rs/bincode2), [`bitcode`](https://docs.rs/bitcode) or
//! [`postcard`](https://docs.rs/postcard)) behave like a self-describing one by transparently
//! serializing a schema alongside (or [separately from](crate::SchemaBuilder)) the data.
//!
//! The main entry point to the crate is [`SelfDescribed`]. For advanced uses [`SchemaBuilder`]
//! and [`Schema`] may also be of interest.
//!
//! See the [README](https://github.com/cristicbz/serde_describe) a detailed discussion of the
//! trade-offs involved.
//!
//! ```
//! use serde::{Deserialize, Serialize};
//! use serde_describe::{Schema, SelfDescribed};
//!
//! // Define a type that non-self-describing formats would generally struggle
//! // with, using skipped fields and untagged unions.
//! #[derive(Debug, PartialEq, Serialize, Deserialize)]
//! struct TopLevel {
//! int32: u32,
//!
//! #[serde(default, skip_serializing_if = "Vec::is_empty")]
//! items: Vec<Item>,
//! }
//!
//! #[derive(Debug, PartialEq, Serialize, Deserialize)]
//! #[serde(untagged)]
//! enum Item {
//! Int(u32),
//! Str(String),
//! }
//!
//! // Serialize a `Vec<TopLevel>` using the `SelfDescribed` wrapper and bitcode, a
//! // particularly restrictive binary format.
//! let original = vec![
//! TopLevel {
//! int32: 10,
//! items: vec![Item::Str("hello".to_owned()), Item::Int(10)],
//! },
//! TopLevel {
//! int32: 20,
//! items: Vec::new(),
//! },
//! ];
//! let bytes = bitcode::serialize(&SelfDescribed(&original))?;
//!
//! // Then deserialize using the same wrapper to use the embedded schema.
//! let roundtripped =
//! bitcode::deserialize::<SelfDescribed<Vec<TopLevel>>>(&bytes)?;
//! assert_eq!(roundtripped, original);
//!
//! # Ok::<_, Box<dyn std::error::Error>>(())
//! ```
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub use ;
pub use ;
pub use Schema;
pub use Trace;