From 045c6aab213aadf4dbb66270ec0d203d7ec762a6 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 28 Jul 2026 18:08:13 +0800 Subject: refactor(dispatcher): replace custom dotted-to-pascal helper with `just_fmt::pascal_case!` --- mingling_macros/src/func/dispatcher.rs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'mingling_macros/src') 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() -} -- cgit