pub struct Environment { /* private fields */ }Expand description
A snapshot of the environment a process was started with.
§Debug redacts
This holds whatever the process was given, which on a configured host includes
LINEAR_API_KEY and GH_PROJECTS_TOKEN. Deriving Debug would put both in
any log line, panic message or {:?} that ever touched one, so the
implementation below prints the names and never a value.
Implementations§
Source§impl Environment
impl Environment
Sourcepub fn from_process() -> Self
pub fn from_process() -> Self
Capture the environment this process was started with.
Read as OS strings rather than through std::env::vars, which panics on an
entry that is not valid Unicode — and a process is handed its environment by
whoever spawned it, so that is an input from outside rather than an invariant.
A name that is not Unicode is dropped: no configuration document, no
ONETASKGRAPH_ variable and no api_key_env: can spell one, so nothing in this
product could ever ask for it. A value that is not Unicode keeps its name in
unusable, where the environment layer turns a
ONETASKGRAPH_-prefixed one into a refusal naming the variable — because a
setting this product cannot read is exactly the thing it may not quietly ignore.
Sourcepub fn from_os_pairs(
pairs: impl IntoIterator<Item = (OsString, OsString)>,
) -> Self
pub fn from_os_pairs( pairs: impl IntoIterator<Item = (OsString, OsString)>, ) -> Self
Build a snapshot from OS strings, sorting out what this product can read.
Separate from from_process so that the sorting is a
function of its argument: a hand-built pair is the only way to drive the two
not-valid-Unicode cases without one process spawning another.
Sourcepub fn from_pairs<K, V>(pairs: impl IntoIterator<Item = (K, V)>) -> Self
pub fn from_pairs<K, V>(pairs: impl IntoIterator<Item = (K, V)>) -> Self
Build a snapshot from explicit pairs.
Sourcepub fn unusable(&self) -> impl Iterator<Item = &str>
pub fn unusable(&self) -> impl Iterator<Item = &str>
Every name this process was given whose value is not valid Unicode.
Sourcepub fn get(&self, name: &str) -> Option<&str>
pub fn get(&self, name: &str) -> Option<&str>
The value of name, or None when the snapshot does not define it.
Sourcepub fn non_empty(&self, name: &str) -> Option<&str>
pub fn non_empty(&self, name: &str) -> Option<&str>
The value of name when it is set to something other than the empty string.
An exported-but-empty variable is how a shell says “unset this for the child”
in practice, and treating XDG_CONFIG_HOME= as a path to the filesystem root
would send discovery somewhere nobody asked for.
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
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 Environment
impl Debug for Environment
Source§impl Default for Environment
impl Default for Environment
Source§fn default() -> Environment
fn default() -> Environment
impl Eq for Environment
Source§impl PartialEq for Environment
impl PartialEq for Environment
impl StructuralPartialEq for Environment
Auto Trait Implementations§
impl Freeze for Environment
impl RefUnwindSafe for Environment
impl Send for Environment
impl Sync for Environment
impl Unpin for Environment
impl UnsafeUnpin for Environment
impl UnwindSafe for Environment
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.