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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
//! The traits of a group and of a key, and the const checks of their names.
use Value;
/// The seal of [`Group`]. A type outside the crate gets [`Group`] through
/// [`UserGroup`] alone.
pub
/// A group of `config`: a single group, such as `[core]`, or a named group,
/// such as `[remote "NAME"]`.
///
/// The trait is sealed. The crate implements it for its own groups, and a
/// blanket impl implements it for each type that implements [`UserGroup`].
/// [`config_group!`](crate::config_group) writes one marker type for each
/// group.
///
/// # Examples
///
/// ```
/// 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"));
/// ```
/// A group of `config` that a library user defines.
///
/// A blanket impl makes each `UserGroup` a [`Group`]. The impl checks the
/// name and the key list at compile time:
///
/// - The group name starts with `ex-`.
/// - The group name is not `ex-integrity` or `ex-ostrya`, and it does not
/// start with `ex-ostrya` and a space. The port uses these names.
/// - The group name holds no `[`, `]`, `"`, or line break.
/// - Each key name is a key that a key file can hold: it is not empty, it
/// does not start or end with a space or a tab, it holds no `=` and no
/// line break, and it does not start with `#` or `[`.
/// - No key name occurs two times.
/// - Each name of [`OVERRIDABLE`](UserGroup::OVERRIDABLE) and of
/// [`SETTABLE`](UserGroup::SETTABLE) is a name of
/// [`KEYS`](UserGroup::KEYS). Both lists of a named group are empty.
///
/// The check fails the build with error E0080 and the text of the rule.
/// [`config_group!`](crate::config_group) runs the check where it defines
/// the group, so a group that no code uses is also checked, and the check
/// fails `cargo check` too. The check of an impl that a caller writes by
/// hand runs when the compiler instantiates a call that uses the group. It
/// fails `cargo build`, and `cargo check` does not run it.
///
/// # Examples
///
/// 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";
/// }
/// }
/// ```
/// One key of the group `G`.
///
/// Each key is a zero-sized type. The type states the key name, the value
/// type, the built-in default, and the type that a read gives.
/// [`config_group!`](crate::config_group) writes these types. A caller can
/// also write the impls by hand. [`Group::KEYS`] must then list
/// [`NAME`](Key::NAME), or a typed read or write of the key does not
/// compile. This check runs when the compiler instantiates the call, so it
/// fails `cargo build`, and `cargo check` does not run it.
///
/// A key type of a library user can name a key that a group of the port
/// lists, for example `fsync` of [`repo::Group`](super::repo::Group). A
/// read of that key type gives the value with the value type of the key
/// type. [`Group::OVERRIDABLE`] and [`Group::SETTABLE`] decide which keys of
/// a group take an override or a create value. An impl of [`Overridable`]
/// or [`Settable`] by a library user changes neither list.
///
/// 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>(())
/// ```
/// A key of a single group.
///
/// The trait names the group of the key, so
/// [`RepoConfig::get`](super::RepoConfig::get) takes the key as its one type
/// argument. [`config_group!`](crate::config_group) implements it for each
/// key of a single group. A key of a named group does not implement it, so
/// a read of such a key on `RepoConfig` does not compile:
///
/// ```
/// 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>(())
/// ```
/// A key of a single group that takes an override of the repository handle.
///
/// [`OpenOptions::force`](crate::OpenOptions::force),
/// [`OpenOptions::fallback`](crate::OpenOptions::fallback), and
/// [`CreateOptions::fallback`](crate::CreateOptions::fallback) take such a
/// key. They also check at compile time that [`Group::OVERRIDABLE`] of the
/// group lists the key.
///
/// The word `overridable` of [`config_group!`](crate::config_group) adds
/// this trait and the name of the key to [`Group::OVERRIDABLE`]. A key that
/// does not implement it takes no override:
///
/// ```
/// 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>();
/// ```
/// A key of a single group that a create can write into a new `config`.
///
/// [`CreateOptions::set`](crate::CreateOptions::set) takes such a key. It
/// also checks at compile time that [`Group::SETTABLE`] of the group lists
/// the key.
///
/// [`config_group!`](crate::config_group) adds this trait to each key of a
/// single group, except a key with the word `fixed`, and adds the name of
/// each such key to [`Group::SETTABLE`]. `[core] mode` and
/// `[core] repo_version` do not implement it, because the create writes
/// them itself:
///
/// ```
/// 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 value type of the key `K` of a single group.
pub type ValueOf<K> = Value;
/// The output type of the key `K` of a single group.
pub type OutputOf<K> = Output;
/// Returns `true` if `s` starts with `prefix`.
const
/// Returns `true` if `a` and `b` are the same text.
pub const
/// Returns `true` if the port uses the group name `name`: `ex-integrity`,
/// `ex-ostrya`, or a name that starts with `ex-ostrya` and a space.
pub const
/// Returns `true` if the group name `name` is empty or holds `[`, `]`, `"`,
/// or a line break.
pub const
/// Returns `true` if a key file can hold the key name `key`.
///
/// The rules are the key rules of [`KeyFile::set_value`]: the key is not
/// empty, does not start or end with a space or a tab, holds no `=` and no
/// line break, and does not start with `#` or `[`.
///
/// [`KeyFile::set_value`]: ostrya_core::KeyFile::set_value
pub const
/// Returns `true` if a name occurs two times in `keys`.
pub const
/// Returns `true` if `keys` holds `key`.
pub const
/// Returns `true` if `keys` holds each name of `names`.
const