#[non_exhaustive]pub struct SpecUnknownEnv {
pub prefix: String,
pub allow: Vec<String>,
}Expand description
Refuse environment variables under the application’s prefix that nothing declares.
unknown_flags "error" turns a misspelled flag into an error. A misspelled or stale
environment variable gets no such check by default — MYAPP_LISTEN_TLS_CRET is read by
nobody, and the program runs on its defaults. That failure is worst where nobody watches a
command line: systemd units, container manifests, Helm values.
unknown_env prefix="MOQ_" {
allow "MOQ_VAAPI_DEVICE" "MOQ_V4L2_ENCODER"
}The prefix only scopes the check. It never builds a name: every variable is still spelled out in full where it is declared, so a name seen in an environment can be found by searching for it.
A variable is known when any flag or argument anywhere in the command tree names it — as
env, an env_fallback or a deprecated_env — or when a config property reads it, or
when it is listed in allow. The whole tree counts, not only the command that ran: a
variable meant for serve is not a typo when the user runs publish. allow is for
variables read outside the spec, such as by a library.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.prefix: StringOnly variables whose names start with this are checked.
allow: Vec<String>Variables under the prefix that the spec does not declare but something still reads.
Implementations§
Source§impl SpecUnknownEnv
impl SpecUnknownEnv
pub fn new(prefix: impl Into<String>) -> Self
Sourcepub fn allow(self, name: impl Into<String>) -> Self
pub fn allow(self, name: impl Into<String>) -> Self
A variable read outside the spec, which is therefore not a mistake.
Sourcepub fn unknown<'n>(
&self,
spec: &Spec,
names: impl IntoIterator<Item = &'n OsStr>,
) -> Vec<String>
pub fn unknown<'n>( &self, spec: &Spec, names: impl IntoIterator<Item = &'n OsStr>, ) -> Vec<String>
The variables under the prefix that spec neither declares nor allows, sorted.
names is the environment’s variable names. A name that is not valid UTF-8 cannot be
one the spec declares, so one under the prefix is reported in its lossy spelling rather
than skipped.
Trait Implementations§
Source§impl Clone for SpecUnknownEnv
impl Clone for SpecUnknownEnv
Source§impl Debug for SpecUnknownEnv
impl Debug for SpecUnknownEnv
Source§impl Default for SpecUnknownEnv
impl Default for SpecUnknownEnv
impl Eq for SpecUnknownEnv
Source§impl PartialEq for SpecUnknownEnv
impl PartialEq for SpecUnknownEnv
Source§impl Serialize for SpecUnknownEnv
impl Serialize for SpecUnknownEnv
impl StructuralPartialEq for SpecUnknownEnv
Auto Trait Implementations§
impl Freeze for SpecUnknownEnv
impl RefUnwindSafe for SpecUnknownEnv
impl Send for SpecUnknownEnv
impl Sync for SpecUnknownEnv
impl Unpin for SpecUnknownEnv
impl UnsafeUnpin for SpecUnknownEnv
impl UnwindSafe for SpecUnknownEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more