Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nhynes/default-env

The `env!` macro but with a default value.
https://github.com/nhynes/default-env

env rust

Last synced: 10 days ago
JSON representation

The `env!` macro but with a default value.

Awesome Lists containing this project

README

        

# default-env

`default_env!` is a macro like [`env!`](https://doc.rust-lang.org/std/macro.env.html) that returns a default value if the environment variable is not found.
Unlike [`option_env!`](https://doc.rust-lang.org/std/macro.option_env.html), the output of `default_env!` can be used in macros (because who doesn't love macros in their macros?).

## Example

```rust
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."))
)
}
}
```