#default-value #env #macro #env-var #option-env

macro default-env

The env! macro but with a default value

2 releases

0.1.1 Jun 21, 2019
0.1.0 Jun 21, 2019

#1668 in Rust patterns

Download history 1753/week @ 2023-11-26 1842/week @ 2023-12-03 1559/week @ 2023-12-10 1600/week @ 2023-12-17 2871/week @ 2023-12-24 3000/week @ 2023-12-31 2242/week @ 2024-01-07 2409/week @ 2024-01-14 2129/week @ 2024-01-21 1968/week @ 2024-01-28 2556/week @ 2024-02-04 3248/week @ 2024-02-11 2856/week @ 2024-02-18 2991/week @ 2024-02-25 3234/week @ 2024-03-03 1259/week @ 2024-03-10

10,597 downloads per month
Used in 10 crates (4 directly)

MIT license

3KB

default-env

default_env! is a macro like env! that returns a default value if the environment variable is not found. Unlike option_env!, the output of default_env! can be used in macros (because who doesn't love macros in their macros?).

Example

macro_rules! long_str {
  () => {
    concat!(
        "Hello, ", default_env!("USER", "anonymous user"), ".",
        "Today is ", default_env!("WEEKDAY", compile_error!("You exist in a land beyond time."))
      )
  }
}

Dependencies

~2MB
~45K SLoC