#macro #constant #const

no-std macro_const

A macro for creating corresponding macro definitions for constants which evaluate to the same values

1 unstable release

0.1.0 Aug 25, 2020

#1215 in Rust patterns

Download history 46/week @ 2021-10-01 61/week @ 2021-10-08 61/week @ 2021-10-15 33/week @ 2021-10-22 1/week @ 2021-10-29 30/week @ 2021-11-05 88/week @ 2021-11-12 149/week @ 2021-11-19 107/week @ 2021-11-26 100/week @ 2021-12-03 173/week @ 2021-12-10 598/week @ 2021-12-17 254/week @ 2021-12-24 72/week @ 2021-12-31 157/week @ 2022-01-07 14/week @ 2022-01-14

500 downloads per month
Used in light-curve-feature

MIT license

3KB

macro_const

Creates corresponding macro definitions for constants, allowing the value of the constants to be used in the context of other macros.

This utility is mostly just for convenience, and for those who did not wish to write the macro themself.

Usage

This crate is available on crates.io. Use the most recent version of this crate when adding it to your dependencies as shown below.

[dependencies]
macro_const = "0.1.0"

View the documentation here for examples.


lib.rs:

Creates corresponding macro definitions for constants, allowing the value of the constants to be used in the context of other macros.

Examples

macro_const! {
const FILE: &str = "message.txt";
}

println!("Contents: {}", include_str!(FILE!()));
println!("File: {}", FILE);

Doc comments can be added as well. The documentation for the constant will be added to the generated macro verbatim. To export the generated macro, simply add the #[macro_export] attribute to the constant definition.

# #[macro_use]
# extern crate macro_const;
# fn main() {
macro_const! {
/// The API base URL.
#[macro_export]
pub const BASE_URL: &str = "https://myapi.io/";

/// The current supported API version.
pub const API_VERSION: &str = "v1";
}

assert_eq!("https://myapi.io/v1", concat!(BASE_URL!(), API_VERSION!()));
# }

No runtime deps

^D_