diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-28 18:08:13 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-28 18:08:13 +0800 |
| commit | 045c6aab213aadf4dbb66270ec0d203d7ec762a6 (patch) | |
| tree | f6f2b5a038cc349ec5d478830e56c99916f90e0e /mingling_macros | |
| parent | ec1420d9d51b78285979a74ccc74c6266344c06f (diff) | |
refactor(dispatcher): replace custom dotted-to-pascal helper with
`just_fmt::pascal_case!`
Diffstat (limited to 'mingling_macros')
| -rw-r--r-- | mingling_macros/src/func/dispatcher.rs | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/mingling_macros/src/func/dispatcher.rs b/mingling_macros/src/func/dispatcher.rs index 4e7c42f..45ac4c8 100644 --- a/mingling_macros/src/func/dispatcher.rs +++ b/mingling_macros/src/func/dispatcher.rs @@ -99,7 +99,7 @@ pub(crate) fn dispatcher(input: TokenStream) -> TokenStream { command_name, } => { let command_name_str = command_name.value(); - let pascal = dotted_to_pascal_case(&command_name_str); + let pascal = just_fmt::pascal_case!(&command_name_str); let command_struct = Ident::new(&format!("CMD{pascal}"), command_name.span()); let pack = Ident::new(&format!("Entry{pascal}"), command_name.span()); (command_name, command_struct, pack, cmd_attrs, Vec::new()) @@ -178,21 +178,3 @@ fn get_dispatch_tree_entry( ) -> TokenStream2 { quote! {} } - -/// Converts a dotted command name (e.g. "remote.add") to `PascalCase` (e.g. "`RemoteAdd`"). -/// -/// Each segment is split by `.`, the first character of each segment is uppercased, -/// and the segments are joined. This is used by the abbreviated `dispatcher!` syntax -/// (when `Command => Entry` is omitted) to auto-derive struct names. -#[cfg(feature = "extra_macros")] -pub(crate) fn dotted_to_pascal_case(s: &str) -> String { - s.split('.') - .map(|segment| { - let mut chars = segment.chars(); - match chars.next() { - None => String::new(), - Some(c) => c.to_uppercase().to_string() + chars.as_str(), - } - }) - .collect() -} |
