#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

#53 in #default-value

Download history 2921/week @ 2024-04-04 4588/week @ 2024-04-11 2656/week @ 2024-04-18 2952/week @ 2024-04-25 2893/week @ 2024-05-02 2804/week @ 2024-05-09 2588/week @ 2024-05-16 2521/week @ 2024-05-23 2273/week @ 2024-05-30 2750/week @ 2024-06-06 3462/week @ 2024-06-13 2763/week @ 2024-06-20 2454/week @ 2024-06-27 2358/week @ 2024-07-04 2437/week @ 2024-07-11 3285/week @ 2024-07-18

10,933 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
~46K SLoC