pub struct Vars { /* private fields */ }Expand description
A small key→value lookup used when expanding $VAR / ${VAR} references.
Vars is checked before falling back to an env lookup (the process
environment by default), so callers can inject locally-scoped values
(e.g. WORKSPACE) without leaking them into global state.
Implementations§
Source§impl Vars
impl Vars
pub fn new() -> Self
Sourcepub fn with_env_lookup(
self,
f: impl Fn(&str) -> Option<String> + Send + Sync + 'static,
) -> Self
pub fn with_env_lookup( self, f: impl Fn(&str) -> Option<String> + Send + Sync + 'static, ) -> Self
Override the env-var fallback. Useful in tests to avoid mutating the process environment.
pub fn with(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn insert( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
pub fn get(&self, key: &str) -> Option<Cow<'_, str>>
Sourcepub fn expand(&self, template: &str) -> Result<String, VarError>
pub fn expand(&self, template: &str) -> Result<String, VarError>
Expand $VAR / ${VAR} references in template, consulting self before
the env lookup. $$ escapes to a literal $.
Sourcepub fn has_reference(&self, s: &str) -> bool
pub fn has_reference(&self, s: &str) -> bool
Returns true if s contains a $VAR or ${VAR} style reference.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Vars
impl !RefUnwindSafe for Vars
impl Send for Vars
impl Sync for Vars
impl Unpin for Vars
impl UnsafeUnpin for Vars
impl !UnwindSafe for Vars
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
Mutably borrows from an owned value. Read more