#env-var #env #proc-macro #compile-time #macro

macro env-smart

Proc macro to insert env vars into code

4 releases (2 stable)

1.0.1 Jan 11, 2024
1.0.0 Dec 19, 2023
1.0.0-alpha.2 Oct 23, 2023

#791 in Procedural macros

49 downloads per month

BSL-1.0 license

12KB
222 lines

env-smart

Rust Crates.io Documentation

Improved version of env! macro from std.

Syntax:

  • Standard env! - If plain string specified then behavior is the same as standard env macro
  • Simplified formatting - Allows to format string using multiple variables enveloped into {} brackets. Note that bracket escaping is not supported

Sources

Macro fetches environment variables in following order:

  • Use .env file from root where build is run. Duplicate values are not allowed.
  • Use current environment where proc macro runs. It will not override .env variables

Usage

use env_smart::env;

static USER_AGENT: &str = env!("{CARGO_PKG_NAME}-{CARGO_PKG_VERSION}");

assert_eq!(USER_AGENT, "env-smart-1.0.0");

No runtime deps