#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

#1723 in Rust patterns

Download history 2495/week @ 2024-01-05 2294/week @ 2024-01-12 2284/week @ 2024-01-19 2021/week @ 2024-01-26 2394/week @ 2024-02-02 2864/week @ 2024-02-09 3325/week @ 2024-02-16 2809/week @ 2024-02-23 2821/week @ 2024-03-01 3590/week @ 2024-03-08 4323/week @ 2024-03-15 3487/week @ 2024-03-22 3184/week @ 2024-03-29 3228/week @ 2024-04-05 4345/week @ 2024-04-12 2167/week @ 2024-04-19

13,445 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