pub struct EnvironmentFile {
pub auth: Option<Auth>,
pub variables: BTreeMap<String, String>,
}Expand description
The on-disk shape of one environment file: every top-level key is a
variable, except auth, which is reserved for an optional default
Auth block — see the module docs and Environment::auth.
auth is the only top-level key this type gives a name to — every other
key becomes a variable, the same way it always has — so a file with no
auth: key behaves exactly like the flat BTreeMap<String, String> this
used to deserialize straight into. The one behavior change this trades
for that continuity: a project that happened to have a variable literally
named auth now needs a different name, or its own auth: block
instead.
Every variable value is a string, and an unquoted YAML scalar becomes
exactly the text it was written as: port: 8080 is the string 8080,
flag: true is true, version: 1.0 is 1.0. That is the only rule
that makes sense for a substitution engine — what is in the file is what
goes into the request, with no round trip through a number or a bool to
round 1.0 down to 1 or to re-spell true as True. Quoting changes
nothing, so '8080' is there for anyone who would rather be explicit.
A variable value that is a sequence or a mapping is a parse error, and
that is the rule keeping environments flat: staging: with variables
nested underneath fails to load rather than half-working — there is no
environment inheritance. auth: is exempt from this — it is a mapping
on purpose — but only auth is; any other nested key is still rejected
exactly as before.
Deserialize is hand-written rather than #[derive(Deserialize)] with
#[serde(flatten)] on variables: flatten deserializes the whole
document through serde’s generic Content capture first, and that
buffering loses serde_yaml’s laxness at the leaves — a captured integer
or float no longer coerces to a string the way a value read straight off
the source text does, and serde_yaml::Value’s own Number has the same
problem (it does not even retain 1.0 vs 1 as written). Either would
silently break every existing environment file with a bare number/bool
value the moment auth: support was added — exactly the backward
compatibility this format change is not allowed to cost. Walking the map
by hand and calling next_value::<String>() per key, below, asks
serde_yaml for a string directly off that key’s own source node, which
is the same call (and the same laxness) BTreeMap<String, String>’s own
Deserialize impl has always made.
Fields§
§auth: Option<Auth>§variables: BTreeMap<String, String>Trait Implementations§
Source§impl Clone for EnvironmentFile
impl Clone for EnvironmentFile
Source§fn clone(&self) -> EnvironmentFile
fn clone(&self) -> EnvironmentFile
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EnvironmentFile
impl Debug for EnvironmentFile
Source§impl Default for EnvironmentFile
impl Default for EnvironmentFile
Source§fn default() -> EnvironmentFile
fn default() -> EnvironmentFile
Source§impl<'de> Deserialize<'de> for EnvironmentFile
impl<'de> Deserialize<'de> for EnvironmentFile
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Serialize for EnvironmentFile
The exact mirror of EnvironmentFile’s hand-written Deserialize
above: auth (when set) plus every variable, all as sibling top-level
keys in one flat map — never {auth: ..., variables: {...}}, which is
what a derived Serialize would produce and not a shape
Deserialize’s own Visitor (or a hand-written
environment file) recognises. Variables are written in BTreeMap order
(i.e. sorted by name) — deterministic, and irrelevant to substitution,
which looks values up by name rather than position. auth is written
first when present, matching the position most hand-written environment
files already put it in (see this module’s own doc comment).
impl Serialize for EnvironmentFile
The exact mirror of EnvironmentFile’s hand-written Deserialize
above: auth (when set) plus every variable, all as sibling top-level
keys in one flat map — never {auth: ..., variables: {...}}, which is
what a derived Serialize would produce and not a shape
Deserialize’s own Visitor (or a hand-written
environment file) recognises. Variables are written in BTreeMap order
(i.e. sorted by name) — deterministic, and irrelevant to substitution,
which looks values up by name rather than position. auth is written
first when present, matching the position most hand-written environment
files already put it in (see this module’s own doc comment).