Skip to main content

Vars

Struct Vars 

Source
pub struct Vars { /* private fields */ }
Expand description

Wrap a HashMap and a default blank value, providing an easy way to get variables, handling special and automatic variables properly.

Implementations§

Source§

impl Vars

Source

pub fn new<const N: usize>(init: [(&str, &str); N]) -> Self

Primary interface for configuring a new instance. We also create some cached values that live for the lifetime of this instance to reduce the number of allocations.

Source

pub fn new_without_builtins<const N: usize>(init: [(&str, &str); N]) -> Self

Like new, but omits make’s built-in tool variables (CC, CFLAGS, COMPILE.c, …) for -R/--no-builtin-variables. The operational specials (.RECIPEPREFIX, .SHELLFLAGS, SHELL, and the suffix list) are always defined so make can still run recipes; env/makefile/command-line definitions are unaffected.

Source

pub fn get(&self, k: impl AsRef<str>) -> &Var

Public interface for getting variables. For unknown keys, the blank object is returned. We should try to keep this interface as fast/simple as possible since it’s used far more often than set (e.g., used for each line to check for recipe prefix).

Source

pub fn is_set(&self, k: impl AsRef<str>) -> bool

Whether a variable is currently defined (including defaults and environment). Used to implement ?= (set-if-undefined) and to pick +=’s behavior.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &Var)>

Iterate over every defined variable as (name, &Var). Used by export-all and $(...) introspection.

Source

pub fn remove(&mut self, k: impl AsRef<str>) -> Option<Var>

Remove a variable (for the undefine directive). Returns its prior Var, if any.

Source

pub fn clear_call_params(&mut self)

Remove the positional call parameters ($(0), $(1), …): every variable whose name is all ASCII digits. $(call ...) uses this so a nested call does not inherit higher-numbered parameters from the enclosing call.

Source

pub fn set<S: Into<String>>( &mut self, k: S, v: S, recursive: bool, ) -> Result<(), String>

Public interface for setting variables. The origin is recorded as File (a makefile assignment); use Vars::set_origin for other origins.

Source

pub fn set_origin<S: Into<String>>( &mut self, k: S, v: S, recursive: bool, origin: Origin, ) -> Result<(), String>

Set a variable, recording where it came from (for $(origin ...)).

Source

pub fn set_exported(&mut self, k: impl AsRef<str>)

Mark a variable exported into recipe child environments (a target-specific export VAR). The variable is expected to already exist; if not, this is a no-op.

Source§

impl Vars

Source

pub fn from_env(env: Env, builtin_vars: bool, env_override: bool) -> Self

Build the variable set from the OS environment. builtin_vars is false under -R, which omits make’s built-in variables so they do not shadow (or appear as) real definitions. env_override is true under -e, which ranks environment variables above makefile assignments: a later unconditional makefile assignment to an environment variable is rejected and its origin becomes EnvironmentOverride (see set_origin).

Trait Implementations§

Source§

impl Clone for Vars

Source§

fn clone(&self) -> Self

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 Vars

Source§

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

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

impl From<HashMap<String, String>> for Vars

Source§

fn from(env: Env) -> Self

Converts to this type from the input type.

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> 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.