#default-value #env #macro

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

#64 in #default-value

Download history 3078/week @ 2024-07-23 2874/week @ 2024-07-30 3705/week @ 2024-08-06 3535/week @ 2024-08-13 3771/week @ 2024-08-20 4417/week @ 2024-08-27 3752/week @ 2024-09-03 3719/week @ 2024-09-10 3261/week @ 2024-09-17 3582/week @ 2024-09-24 3152/week @ 2024-10-01 3012/week @ 2024-10-08 4594/week @ 2024-10-15 4563/week @ 2024-10-22 4308/week @ 2024-10-29 4371/week @ 2024-11-05

18,483 downloads per month
Used in 12 crates (5 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
~48K SLoC