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(s: &str) -> bool
pub fn has_reference(s: &str) -> bool
Returns true if s contains a $VAR or ${VAR} style reference.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Vars
impl !UnwindSafe for Vars
impl Forget for Vars
impl Freeze for Varswhere
*const LeafNode<String, String> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, String)>>: Freeze,
*const ArcInner<dyn Fn(&str) -> Option<String> + Send + Sync> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(&str) -> Option<String> + Send + Sync>>: Freeze,
impl Move for Vars
impl Send for Vars
impl Sync for Vars
impl Unpin for Vars
impl UnsafeUnpin for Varswhere
*const LeafNode<String, String> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, String)>>: UnsafeUnpin,
*const ArcInner<dyn Fn(&str) -> Option<String> + Send + Sync> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(&str) -> Option<String> + Send + Sync>>: UnsafeUnpin,
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