Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/nhynes/default-env
- Owner: nhynes
- Created: 2019-06-21T02:27:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-21T19:43:22.000Z (over 1 year ago)
- Last Synced: 2024-10-12T12:17:17.793Z (26 days ago)
- Topics: env, rust
- Language: Rust
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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."))
)
}
}
```