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
//! Reading the `VITRI_*` environment variables.
//!
//! One rule, for every knob: unset means the documented default.
//!
//! Each reader here comes in two halves: a pure function over the value, so the
//! accepted spellings can be tested without mutating the process environment,
//! and a thin reader that fetches the variable and hands it over.
//!
//! How a value is written is settled here too, once, for every knob: the shell
//! that exports one leaves whitespace around it easily and none of these values
//! is whitespace, so surrounding whitespace is not part of the value; and where
//! a value is a *word* rather than a number, the word is read regardless of
//! case. [`is_form`] is that rule, and every vocabulary in the crate matches
//! through it.
use FromStr;
use crateVitriError;
/// The spellings a flag accepts, quoted in its error message so the message and
/// the parser cannot drift apart.
const FLAG_FORMS: &str = "1, on or true (on), or 0, off or false (off)";
/// [`FLAG_FORMS`] plus what UNSET means for the knob at hand. Most knobs ship
/// off, but a knob whose production setting is ON has to say so, or its error
/// message tells the reader the opposite of what the code does.
/// The raw value of `name`, if it is set at all.
///
/// # Errors
///
/// [`VitriError::Env`] when the variable is set to a non-UTF-8 value.
pub
/// The raw value of `name` for a knob that TOLERATES a value it cannot use.
///
/// The one shape here with no `expected` clause and no error: a caller that
/// reads an unusable value as unset has no message to put one in. Bytes that
/// are not UTF-8 read as unset for the same reason the unparseable ones do.
/// [`crate::config::RunConfig::budget_ms`]'s default is the only knob of this
/// kind, and `docs/env.md` records that it is.
pub
/// Parse an already-read value as `T`. The pure half of [`parse`].
///
/// # Errors
///
/// [`VitriError::Env`] when `value` is `Some` and does not parse as `T`.
pub
/// Whether `value` is written as `form` — the one rule for reading a knob whose
/// value is a word (see the module header).
pub
/// Read an already-read value against an enumerated vocabulary. The pure half
/// of every knob whose values are words.
///
/// `forms` is searched in order, through [`is_form`]; `expected` states the
/// vocabulary in the words of whoever sets the variable and is quoted verbatim
/// in the message, so the vocabulary and its description sit at one site.
///
/// # Errors
///
/// [`VitriError::Env`] when `value` is `Some` and is none of the `forms`.
pub
/// Parse environment variable `name` as `T`.
///
/// `expected` states the accepted form in the words of whoever sets the
/// variable ("a number of milliseconds", not "u64") — it is quoted verbatim in
/// the message.
///
/// # Errors
///
/// [`VitriError::Env`] when the variable is set to a value that does not parse
/// as `T`, or to bytes that are not UTF-8.
pub
/// Read an already-read value as an on/off flag. The pure half of
/// [`env_flag_or`].
///
/// The empty string is an error, not treated as unset.
///
/// # Errors
///
/// [`VitriError::Env`] when `value` is `Some` and matches none of the accepted
/// spellings.
pub
/// Read environment variable `name` as an on/off flag that is OFF when unset —
/// which is every switch that ships disabled.
///
/// # Errors
///
/// [`VitriError::Env`] when the variable is set to something that is neither an
/// on nor an off spelling.
pub
/// Read environment variable `name` as an on/off flag whose meaning when UNSET
/// is `default`, over [`flag_value`]. [`env_flag`] is this with `default =
/// false`; a switch whose production setting is on takes the other one, so that
/// turning it off is spelled the same way as turning anything else on.
///
/// # Errors
///
/// [`VitriError::Env`] when the variable is set to something that is neither an
/// on nor an off spelling.
pub