diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-17 21:33:40 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-17 21:57:13 +0800 |
| commit | ad0943f88ba9f5ed6eae198ecb4835c0f44701de (patch) | |
| tree | 6a8eb1fee42e7ee173e74788dafeb27c52429683 /rola-vcs/internal_macros/src/lib.rs | |
chore: initialize project structure and add core modules
Diffstat (limited to 'rola-vcs/internal_macros/src/lib.rs')
| -rw-r--r-- | rola-vcs/internal_macros/src/lib.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/rola-vcs/internal_macros/src/lib.rs b/rola-vcs/internal_macros/src/lib.rs new file mode 100644 index 0000000..f6c3cb7 --- /dev/null +++ b/rola-vcs/internal_macros/src/lib.rs @@ -0,0 +1,39 @@ +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<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) +} |
