env_ast 1.0.0

env! but it outputs tokens instead of a string literal
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 7.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 270.16 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • WilliamVenner/env_ast
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • WilliamVenner

crates.io docs.rs license

env_ast

Dead simple procedural macro that mimics env! 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 file:

[dependencies]
env_ast = "*"

And in your code:

#[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
}