Skip to main content

EnvironmentFile

Struct EnvironmentFile 

Source
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

Source§

fn clone(&self) -> EnvironmentFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EnvironmentFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EnvironmentFile

Source§

fn default() -> EnvironmentFile

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for EnvironmentFile

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
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).

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more