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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//! The examples of the traits of a group and of a key, of the macro
//! `config_group!`, and of `Section`.
//!
//! The traits, the macro, and `Section` are in `ostrya-core`. These examples
//! use `RepoConfig` and the groups of this crate, so rustdoc runs them from
//! this module.
/// The examples of `Group`.
///
/// ```
/// use ostrya::config::{Group, repo};
///
/// assert_eq!(<repo::Group as Group>::NAME, "core");
/// assert!(!<repo::Group as Group>::NAMED);
/// assert!(<repo::Group as Group>::KEYS.contains(&"fsync"));
/// ```
;
/// The examples of `UserGroup`.
///
/// A group with the name `ex-debles` compiles:
///
/// ```
/// ostrya::config_group! {
/// pub group debles = "ex-debles" {
/// Target: Option<String> = "target";
/// }
/// }
/// ```
///
/// The port reserves `ex-ostrya` and each name that starts with `ex-ostrya`
/// and a space:
///
/// ```compile_fail,E0080
/// ostrya::config_group! {
/// pub group server = "ex-ostrya server" {
/// Target: Option<String> = "target";
/// }
/// }
/// ```
///
/// A user group name starts with `ex-`:
///
/// ```compile_fail,E0080
/// ostrya::config_group! {
/// pub group debles = "debles" {
/// Target: Option<String> = "target";
/// }
/// }
/// ```
;
/// The examples of `Key`.
///
/// A read of a section takes a key of the group of the section alone:
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
/// pub group a = named "ex-a" {
/// X: Option<String> = "x";
/// }
/// }
/// ostrya::config_group! {
/// pub group b = named "ex-b" {
/// X: Option<String> = "x";
/// }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n[ex-a \"s\"]\nx=1\n")?;
/// let section = cfg.section::<a::Group>("s").unwrap();
/// assert_eq!(section.get::<a::X>()?.as_deref(), Some("1"));
/// # Ok::<(), ostrya::Error>(())
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
/// pub group a = named "ex-a" {
/// X: Option<String> = "x";
/// }
/// }
/// ostrya::config_group! {
/// pub group b = named "ex-b" {
/// X: Option<String> = "x";
/// }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n[ex-a \"s\"]\nx=1\n")?;
/// let section = cfg.section::<a::Group>("s").unwrap();
/// let _ = section.get::<b::X>()?;
/// # Ok::<(), ostrya::Error>(())
/// ```
;
/// The examples of `SingleKey`.
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
/// pub group tool = "ex-tool" {
/// Jobs: u32 = "jobs", default 4;
/// }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n")?;
/// assert_eq!(cfg.get::<tool::Jobs>()?, 4);
/// # Ok::<(), ostrya::Error>(())
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
/// pub group tool = named "ex-tool" {
/// Jobs: u32 = "jobs", default 4;
/// }
/// }
///
/// let cfg = RepoConfig::parse("[core]\nrepo_version=1\nmode=bare\n")?;
/// let _ = cfg.get::<tool::Jobs>()?;
/// # Ok::<(), ostrya::Error>(())
/// ```
;
/// The examples of `Overridable`.
///
/// ```
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Fsync>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Mode>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::Locking>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::DisableXattrs>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, repo};
///
/// fn takes<K: Overridable>() {}
/// takes::<repo::CollectionId>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Overridable, ex_ostrya};
///
/// fn takes<K: Overridable>() {}
/// takes::<ex_ostrya::RemotesConfigDir>();
/// ```
;
/// The examples of `Settable`.
///
///
/// ```
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::Locking>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::Mode>();
/// ```
///
/// ```compile_fail,E0277
/// use ostrya::config::{Settable, repo};
///
/// fn takes<K: Settable>() {}
/// takes::<repo::RepoVersion>();
/// ```
///
/// A key of a library user without the word `fixed` implements the trait:
///
/// ```
/// use ostrya::config::Settable;
///
/// ostrya::config_group! {
/// pub group tool = "ex-tool" {
/// Strict: bool = "strict", default false;
/// }
/// }
///
/// fn takes<K: Settable>() {}
/// takes::<tool::Strict>();
/// ```
///
/// The word `fixed` removes the trait:
///
/// ```compile_fail,E0277
/// use ostrya::config::Settable;
///
/// ostrya::config_group! {
/// pub group tool = "ex-tool" {
/// Strict: bool = "strict", default false, fixed;
/// }
/// }
///
/// fn takes<K: Settable>() {}
/// takes::<tool::Strict>();
/// ```
;
/// The examples of `config_group!`.
///
/// ```
/// use ostrya::config::{Group, RepoConfig};
///
/// ostrya::config_group! {
/// /// The keys of the `debles` tool.
/// pub group debles = "ex-debles" {
/// /// The target of a build.
/// Target: Option<String> = "target";
/// /// The number of parallel jobs.
/// Parallel: u32 = "parallel", default 4, overridable;
/// }
/// }
///
/// ostrya::config_group! {
/// /// The images of the `debles` tool.
/// pub group image = named "ex-debles image", closed {
/// /// The architecture of an image.
/// Arch: String = "arch", required;
/// }
/// }
///
/// let cfg = RepoConfig::parse(
/// "[core]\nrepo_version=1\nmode=bare\n\
/// [ex-debles]\ntarget=x86\n\
/// [ex-debles image \"base\"]\narch=amd64\n",
/// )?;
/// assert_eq!(cfg.get::<debles::Target>()?.as_deref(), Some("x86"));
/// assert_eq!(cfg.get::<debles::Parallel>()?, 4);
/// for image in cfg.sections::<image::Group>() {
/// assert_eq!(image.name(), "base");
/// assert_eq!(image.get::<image::Arch>()?, "amd64");
/// }
/// assert!(<image::Group as Group>::CLOSED);
/// # Ok::<(), ostrya::Error>(())
/// ```
;
/// The examples of `Section`.
///
/// ```
/// use ostrya::config::RepoConfig;
///
/// ostrya::config_group! {
/// pub group image = named "ex-image", closed {
/// Arch: Option<String> = "arch";
/// }
/// }
///
/// let cfg = RepoConfig::parse(
/// "[core]\nrepo_version=1\nmode=bare\n[ex-image \"base\"]\narch=x86\nzzz=1\n",
/// )?;
/// let base = cfg.section::<image::Group>("base").unwrap();
/// assert_eq!(
/// base.refuse_unknown_keys().unwrap_err().to_string(),
/// "invalid format: [ex-image \"base\"] holds the unknown key 'zzz'"
/// );
/// # Ok::<(), ostrya::Error>(())
/// ```
;