Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Created June 12, 2026 20:15
Show Gist options
  • Select an option

  • Save malcolmgreaves/a7ff37a6394f9212af6ab7df956dbe55 to your computer and use it in GitHub Desktop.

Select an option

Save malcolmgreaves/a7ff37a6394f9212af6ab7df956dbe55 to your computer and use it in GitHub Desktop.
Creates a new `pub const &str` that is called `ENV_(string you put in)` and has the exact value of what you put in.
/// Creates a new `pub const &str` that is called `ENV_(string you put in)` and has the exact value of what you put in.
///
/// Example:
///
/// named_env_var!("FOO");
/// assert_eq!(ENV_FOO, "FOO");
///
macro_rules! named_env_var {
($name:expr) => {
pub const concat!("ENV_", $name): &str = $name;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment