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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// avoid hits for tests/examples but see alwo workspace lints
//! Derive macros for `miniconf` trees.
//!
//! Most users import these macros through `miniconf` and write `#[derive(Tree)]`.
//! `Tree` is shorthand for `TreeSchema`, `TreeSerialize`, `TreeDeserialize`, and
//! `TreeAny` on the same item.
//!
//! # Tree Shape
//!
//! Fields and variants are internal nodes when their types implement the relevant
//! `Tree*` traits. Serde leaves are accessed directly. Use
//! `#[tree(with = miniconf::leaf)]` to force a `Tree`-capable type to stay one
//! leaf value.
//!
//! ```ignore
//! use miniconf::{leaf, Tree};
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Serialize, Deserialize)]
//! struct Calibration {
//! offset: i32,
//! scale: u16,
//! }
//!
//! #[derive(Tree)]
//! struct Settings {
//! #[tree(rename = "cal", with = leaf)]
//! calibration: Calibration,
//! }
//! ```
//!
//! # Attributes
//!
//! `#[tree(...)]` is accepted on containers, fields, and variants:
//!
//! - `rename = ident` exposes a different Rust identifier as the path segment.
//! - `skip` removes the field or variant from the tree.
//! - `flatten` splices one child tree into the parent when lookup is unambiguous.
//! - `with = module` delegates schema, serialization, deserialization, and `Any`
//! access to functions in `module`.
//! - `meta(key = "value")` attaches reflection metadata.
//! - `meta(key)` inherits supported metadata from Rust syntax: `doc`,
//! `typename`, or `nullable`.
//!
//! Container `meta(doc)` stores Rust doc comments as node metadata.
//! `meta(typename)` stores the Rust type name. Field and variant metadata is
//! edge metadata unless the item is flattened into the parent.
//!
//! ```ignore
//! use miniconf::Tree;
//!
//! /// Node documentation copied by `meta(doc)`.
//! #[derive(Tree)]
//! #[tree(meta(doc, typename))]
//! struct Settings {
//! #[tree(rename = "en")]
//! enabled: bool,
//! #[tree(skip)]
//! cache_only: u32,
//! }
//! ```
//!
//! # Custom Access
//!
//! `with = module` is the escape hatch for validation, read-only leaves, relaxed
//! bounds, or nonstandard access. The module exports the operations the derive
//! calls, such as `schema::<T>()`, `serialize_by_key`, `deserialize_by_key`,
//! `probe_by_key`, `ref_any_by_key`, and `mut_any_by_key`.
//!
//! Custom deserialize bounds may refer to the generated deserialize lifetime as
//! `'__de`.
//!
//! Prefer this for real access policy. Keep ordinary Serde leaves on the default
//! path or use `with = miniconf::leaf`.
//!
//! # Limits
//!
//! - Internal tree enums support unit, newtype, and skipped variants only.
//! - Enums with named fields or multi-field tuple variants should stay leaves or
//! use a manual/custom implementation.
//! - Flattening is supported only when generated lookup stays unambiguous.
use FromDeriveInput;
use TokenStream;
use ;
use Tree;
/// Derive the `TreeSchema` trait for a struct or enum.
/// Derive the `TreeSerialize` trait for a struct or enum.
/// Derive the `TreeDeserialize` trait for a struct or enum.
/// Derive the `TreeAny` trait for a struct or enum.
/// Derive the `TreeSchema`, `TreeSerialize`, `TreeDeserialize`, and `TreeAny` traits for a struct or enum.
///
/// This is a shorthand to derive multiple traits.