mod constants; use proc_macro::TokenStream; /// Transforms `pub const` items in a module into equivalent functions. /// /// Constants without `{param}` placeholders become `fn NAME() -> String`. /// Constants with `{param}` placeholders become `fn NAME(param: impl AsRef) -> String`, /// using `format!()` to fill in the placeholders. /// /// The entire module is annotated with `#[allow(non_snake_case)]`. /// /// # Example /// /// ```ignore /// #[rorolala_internal_macros::constants] /// pub mod paths { /// pub const ROLA_DRAFT_DIR: &str = ".rola"; /// pub const ROLA_BINDED_BUCKET_FILE: &str = ".rola/BIND/{bucket}"; /// } /// ``` /// /// expands to: /// /// ```ignore /// #[allow(non_snake_case)] /// pub mod paths { /// pub fn ROLA_DRAFT_DIR() -> String { /// ".rola".to_string() /// } /// pub fn ROLA_BINDED_BUCKET_FILE(bucket: impl AsRef) -> String { /// format!(".rola/BIND/{bucket}", bucket = bucket.as_ref()) /// } /// } /// ``` #[proc_macro_attribute] pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream { constants::expand(attr, item) }