diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-18 02:47:32 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-18 02:47:32 +0800 |
| commit | 0b8e6e7d18abb94bd99553dc1d2b0ba5d4f265ea (patch) | |
| tree | 97a7c3430d56bfcb885cbfff0b011362671dd474 /rola-utils/macros/src/lib.rs | |
| parent | ebd46942c3fcc7939e5567a797a55198148301ea (diff) | |
refactor: extract shared utilities and add space-system crate
Extract rola-vcs/internal_macros into shared utils crates
(shared_constants, shared_macros, space-system) and implement
the Bucket enum with async space management
Diffstat (limited to 'rola-utils/macros/src/lib.rs')
| -rw-r--r-- | rola-utils/macros/src/lib.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/rola-utils/macros/src/lib.rs b/rola-utils/macros/src/lib.rs index 8b13789..46762e3 100644 --- a/rola-utils/macros/src/lib.rs +++ b/rola-utils/macros/src/lib.rs @@ -1 +1,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) +} |
