https://github.com/williamvenner/env_ast
env! but it outputs tokens instead of a string literal
https://github.com/williamvenner/env_ast
env env-vars environment environment-variables gh-actions github-actions macro proc-macro rust
Last synced: 7 months ago
JSON representation
env! but it outputs tokens instead of a string literal
- Host: GitHub
- URL: https://github.com/williamvenner/env_ast
- Owner: WilliamVenner
- License: mit
- Created: 2022-02-08T15:38:50.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-08T15:58:13.000Z (over 3 years ago)
- Last Synced: 2024-10-11T11:33:43.031Z (about 1 year ago)
- Topics: env, env-vars, environment, environment-variables, gh-actions, github-actions, macro, proc-macro, rust
- Language: Rust
- Homepage: https://docs.rs/env_ast/
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://crates.io/crates/env_ast)
[](https://docs.rs/env_ast/)
[](https://github.com/WilliamVenner/env_ast/blob/master/LICENSE)# env_ast
Dead simple procedural macro that mimics [`env!`](https://doc.rust-lang.org/std/env/index.html) but outputs AST tokens instead of a string literal.
**WARNING:** This macro is potentially DANGEROUS and can introduce arbitrary code execution (ACE) if used improperly. If you need this macro, make sure you REALLY need it.
# Usage
Simply add to your [Cargo.toml](https://doc.rust-lang.org/cargo/reference/manifest.html) file:
```toml
[dependencies]
env_ast = "*"
```And in your code:
```rust
#[macro_use] extern crate env_ast;fn it_works() {}
fn default_works() {}fn main() {
env_ast!("MY_ENV_VAR")(); // For this to compile, MY_ENV_VAR must be set to `it_works` at build time
env_ast!("ENV_VAR_THAT_IS_NOT_SET", default_works)(); // You can provide a default set of tokens if the environment variable is not found
}
```