blob: 46762e38434d571d2c36d2a190249e7771bca72e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use proc_macro::TokenStream;
mod constants;
/// 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<str>) -> 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<str>) -> String {
/// format!(".rola/BIND/{bucket}", bucket = bucket.as_ref())
/// }
/// }
/// ```
#[proc_macro_attribute]
pub fn constants(attr: TokenStream, item: TokenStream) -> TokenStream {
constants::expand(attr, item)
}
|