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
//! The one-code-per-value contract, derived rather than written out.
//!
//! [`string_codes!`] takes a type with
//!
//! - `pub const ALL: [Self; N]` — every variant, in declaration order, and
//! - `pub const fn as_str(self) -> &'static str` — the code,
//!
//! and derives `CODES`, [`Display`](std::fmt::Display) and
//! [`FromStr`](std::str::FromStr). `CODES` is *computed* from `ALL` in a
//! `const` block, so the two cannot disagree: adding a variant extends both or
//! fails to compile. A database `CHECK` constraint generated from `CODES`
//! therefore cannot drift from what the crate writes.
//!
//! Enums carrying data — [`MeasurementSource`](crate::MeasurementSource),
//! [`AggregationRule`](crate::AggregationRule),
//! [`Capability`](crate::Capability) — are not codes; a variant plus its
//! payload has no single string. Each carries a coded discriminator instead.
/// Derive `CODES`, [`Display`](std::fmt::Display) and
/// [`FromStr`](std::str::FromStr) for a coded enum.
///
/// See the [module docs](self) for the contract. Each entry is a type, and
/// optionally a list of lenient input aliases that are accepted on the way in
/// and never written on the way out:
///
/// ```text
/// string_codes! {
/// Messtyp;
/// Sparte, aliases = [("WÄRME", Self::Waerme)];
/// }
/// ```
;
}
)+};
}
pub use string_codes;