From 320ea9a3a418daa17174dc78f1262509b96b13b9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 19 Jul 2026 10:32:33 +0800 Subject: fix!: rename `Groupped` to `Grouped` across the codebase --- mingling_macros/src/chain.rs | 4 +- mingling_macros/src/dispatcher.rs | 2 +- mingling_macros/src/group_impl.rs | 4 +- mingling_macros/src/grouped.rs | 79 +++++++++++++++++++++++++++++++++ mingling_macros/src/groupped.rs | 79 --------------------------------- mingling_macros/src/lib.rs | 80 +++++++++++++++++----------------- mingling_macros/src/pack.rs | 2 +- mingling_macros/src/pack_err.rs | 8 ++-- mingling_macros/src/structural_data.rs | 4 +- 9 files changed, 131 insertions(+), 131 deletions(-) create mode 100644 mingling_macros/src/grouped.rs delete mode 100644 mingling_macros/src/groupped.rs (limited to 'mingling_macros') diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index 566e782..ef31854 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -62,13 +62,13 @@ fn generate_proc_fn( quote! { #(#immut_resource_stmts)* #wrapped_body; - > + > ::to_chain(crate::ResultEmpty) } } else { quote! { #wrapped_body; - > + > ::to_chain(crate::ResultEmpty) } }; diff --git a/mingling_macros/src/dispatcher.rs b/mingling_macros/src/dispatcher.rs index 2a7c850..3698ede 100644 --- a/mingling_macros/src/dispatcher.rs +++ b/mingling_macros/src/dispatcher.rs @@ -134,7 +134,7 @@ pub fn dispatcher(input: TokenStream) -> TokenStream { ::mingling::macros::node!(#command_name_str) } fn begin(&self, args: Vec) -> ::mingling::ChainProcess<#program_type> { - use ::mingling::Groupped; + use ::mingling::Grouped; #pack::new(args).to_chain() } fn clone_dispatcher(&self) -> Box> { diff --git a/mingling_macros/src/group_impl.rs b/mingling_macros/src/group_impl.rs index 59da9dd..cac2734 100644 --- a/mingling_macros/src/group_impl.rs +++ b/mingling_macros/src/group_impl.rs @@ -124,7 +124,7 @@ pub fn group_macro(input: TokenStream) -> TokenStream { quote! {} }; - // Generate the module with the Groupped implementation + // Generate the module with the Grouped implementation let expanded = quote! { #alias_stmt #[allow(non_camel_case_types)] @@ -133,7 +133,7 @@ pub fn group_macro(input: TokenStream) -> TokenStream { #type_use #alias_use - impl ::mingling::Groupped<__MinglingProgram> for #type_name { + impl ::mingling::Grouped<__MinglingProgram> for #type_name { fn member_id() -> __MinglingProgram { __MinglingProgram::#type_name } diff --git a/mingling_macros/src/grouped.rs b/mingling_macros/src/grouped.rs new file mode 100644 index 0000000..9014c37 --- /dev/null +++ b/mingling_macros/src/grouped.rs @@ -0,0 +1,79 @@ +use proc_macro::TokenStream; +use quote::quote; +use syn::{DeriveInput, Ident, parse_macro_input}; + +pub fn derive_grouped(input: TokenStream) -> TokenStream { + // Parse the input struct/enum + let input = parse_macro_input!(input as DeriveInput); + let struct_name = input.ident; + + let group_ident: proc_macro2::TokenStream = crate::default_program_path(); + + let any_output_convert_impls = + proc_macro2::TokenStream::from(build_any_output_convert_impls(&struct_name, &group_ident)); + + // Generate the Grouped trait implementation + let expanded = quote! { + ::mingling::macros::register_type!(#struct_name); + + impl ::mingling::Grouped<#group_ident> for #struct_name { + fn member_id() -> #group_ident { + #group_ident::#struct_name + } + } + + #any_output_convert_impls + }; + + expanded.into() +} + +#[cfg(feature = "structural_renderer")] +pub fn derive_grouped_serialize(input: TokenStream) -> TokenStream { + // Parse the input struct/enum + let input_parsed = parse_macro_input!(input as DeriveInput); + let struct_name = input_parsed.ident.clone(); + + let group_ident: proc_macro2::TokenStream = crate::default_program_path(); + + let any_output_convert_impls = + proc_macro2::TokenStream::from(build_any_output_convert_impls(&struct_name, &group_ident)); + + // Generate both Serialize and Grouped implementations + let expanded = quote! { + #[derive(serde::Serialize)] + #input_parsed + + ::mingling::macros::register_type!(#struct_name); + + impl ::mingling::Grouped<#group_ident> for #struct_name { + fn member_id() -> #group_ident { + #group_ident::#struct_name + } + } + + #any_output_convert_impls + }; + + expanded.into() +} + +fn build_any_output_convert_impls( + struct_name: &Ident, + group_ident: &proc_macro2::TokenStream, +) -> TokenStream { + quote! { + impl ::std::convert::Into<::mingling::AnyOutput<#group_ident>> for #struct_name { + fn into(self) -> ::mingling::AnyOutput<#group_ident> { + ::mingling::AnyOutput::new(self) + } + } + + impl ::std::convert::Into<::mingling::ChainProcess<#group_ident>> for #struct_name { + fn into(self) -> ::mingling::ChainProcess<#group_ident> { + ::mingling::AnyOutput::new(self).route_chain() + } + } + } + .into() +} diff --git a/mingling_macros/src/groupped.rs b/mingling_macros/src/groupped.rs deleted file mode 100644 index 8aee003..0000000 --- a/mingling_macros/src/groupped.rs +++ /dev/null @@ -1,79 +0,0 @@ -use proc_macro::TokenStream; -use quote::quote; -use syn::{DeriveInput, Ident, parse_macro_input}; - -pub fn derive_groupped(input: TokenStream) -> TokenStream { - // Parse the input struct/enum - let input = parse_macro_input!(input as DeriveInput); - let struct_name = input.ident; - - let group_ident: proc_macro2::TokenStream = crate::default_program_path(); - - let any_output_convert_impls = - proc_macro2::TokenStream::from(build_any_output_convert_impls(&struct_name, &group_ident)); - - // Generate the Groupped trait implementation - let expanded = quote! { - ::mingling::macros::register_type!(#struct_name); - - impl ::mingling::Groupped<#group_ident> for #struct_name { - fn member_id() -> #group_ident { - #group_ident::#struct_name - } - } - - #any_output_convert_impls - }; - - expanded.into() -} - -#[cfg(feature = "structural_renderer")] -pub fn derive_groupped_serialize(input: TokenStream) -> TokenStream { - // Parse the input struct/enum - let input_parsed = parse_macro_input!(input as DeriveInput); - let struct_name = input_parsed.ident.clone(); - - let group_ident: proc_macro2::TokenStream = crate::default_program_path(); - - let any_output_convert_impls = - proc_macro2::TokenStream::from(build_any_output_convert_impls(&struct_name, &group_ident)); - - // Generate both Serialize and Groupped implementations - let expanded = quote! { - #[derive(serde::Serialize)] - #input_parsed - - ::mingling::macros::register_type!(#struct_name); - - impl ::mingling::Groupped<#group_ident> for #struct_name { - fn member_id() -> #group_ident { - #group_ident::#struct_name - } - } - - #any_output_convert_impls - }; - - expanded.into() -} - -fn build_any_output_convert_impls( - struct_name: &Ident, - group_ident: &proc_macro2::TokenStream, -) -> TokenStream { - quote! { - impl ::std::convert::Into<::mingling::AnyOutput<#group_ident>> for #struct_name { - fn into(self) -> ::mingling::AnyOutput<#group_ident> { - ::mingling::AnyOutput::new(self) - } - } - - impl ::std::convert::Into<::mingling::ChainProcess<#group_ident>> for #struct_name { - fn into(self) -> ::mingling::ChainProcess<#group_ident> { - ::mingling::AnyOutput::new(self).route_chain() - } - } - } - .into() -} diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 9419f39..77e1137 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -13,7 +13,7 @@ //! ┌──────────────────────────────────────────────────────────────────┐ //! │ Phase 1: Declaration │ //! │ │ -//! │ dispatcher! pack! node! #[derive(Groupped)] │ +//! │ dispatcher! pack! node! #[derive(Grouped)] │ //! │ │ │ │ │ │ //! │ V V V V │ //! │ Declares Wraps a Builds Makes a type │ @@ -55,7 +55,7 @@ //! | `pack_err!` | Creates an error struct with automatic `name` field | //! | `pack_err_structural!` | Like `pack_err!` but also derives `StructuralData` for structured output | //! | `entry!` | Creates a packed entry from string literals | -//! | [`#[derive(Groupped)]`](derive@Groupped) | Makes a type recognizable by the framework's type registry | +//! | [`#[derive(Grouped)]`](derive@Grouped) | Makes a type recognizable by the framework's type registry | //! | `#[derive(StructuralData)]` | Marks a type as eligible for structured output (JSON/YAML/etc.) | //! | [`#[derive(EnumTag)]`](derive@EnumTag) | Adds enum variant metadata (name, description) | //! @@ -161,7 +161,7 @@ mod entry; mod enum_tag; #[cfg(feature = "extra_macros")] mod group_impl; -mod groupped; +mod grouped; mod help; mod node; mod pack; @@ -265,7 +265,7 @@ fn entry_has_variant(entry: &str, variant_name: &str) -> bool { /// Registers an outside-type as a member of a program group without modifying its definition. /// /// This macro allows you to use outside-types from external crates (like `std::io::Error`) -/// within the Mingling framework by generating a `Groupped` implementation and registering +/// within the Mingling framework by generating a `Grouped` implementation and registering /// the type's simple name as an enum variant. /// /// # Syntax @@ -281,11 +281,11 @@ fn entry_has_variant(entry: &str, variant_name: &str) -> bool { /// /// The macro generates a module containing: /// - A `use` import for the program path and the outside-type -/// - An `impl Groupped` for the outside-type +/// - An `impl Grouped` for the outside-type /// - A `register_type!` call with the type's simple name /// /// The type's simple name (e.g. `Error`) is used as the enum variant in the generated -/// program enum, just like `#[derive(Groupped)]` or `pack!`. +/// program enum, just like `#[derive(Grouped)]` or `pack!`. /// /// # Example /// @@ -297,7 +297,7 @@ fn entry_has_variant(entry: &str, variant_name: &str) -> bool { /// ``` /// /// After expansion, the type can be used in chains and renderers like any -/// `#[derive(Groupped)]` type. +/// `#[derive(Grouped)]` type. /// /// This macro is only available with the `extra_macros` feature. #[cfg(feature = "extra_macros")] @@ -402,7 +402,7 @@ pub fn node(input: TokenStream) -> TokenStream { /// - `AsRef`, `AsMut` /// - `Default` if `String: Default` /// - `Into>`, `Into>` -/// - Implements `Groupped` with `member_id()` returning the enum variant +/// - Implements `Grouped` with `member_id()` returning the enum variant /// /// The struct is also registered via `register_type!` so that `gen_program!` /// can include it in the program enum. @@ -438,7 +438,7 @@ pub fn pack_structural(input: TokenStream) -> TokenStream { /// Creates an error struct with a `name: String` field and optional `info: Type` field. /// -/// This macro provides a concise way to define error types that implement `Groupped` +/// This macro provides a concise way to define error types that implement `Grouped` /// and are registered for inclusion in the program enum. /// /// The `name` field is automatically set to the snake_case version of the struct name @@ -461,7 +461,7 @@ pub fn pack_structural(input: TokenStream) -> TokenStream { /// For `pack_err!(ErrorNotFound)`: /// /// ```rust,ignore -/// #[derive(::mingling::Groupped)] +/// #[derive(::mingling::Grouped)] /// pub struct ErrorNotFound { /// name: String, /// } @@ -478,7 +478,7 @@ pub fn pack_structural(input: TokenStream) -> TokenStream { /// For `pack_err!(ErrorNotDir = PathBuf)`: /// /// ```rust,ignore -/// #[derive(::mingling::Groupped)] +/// #[derive(::mingling::Grouped)] /// pub struct ErrorNotDir { /// name: String, /// info: PathBuf, @@ -528,13 +528,13 @@ pub fn pack_err_structural(input: TokenStream) -> TokenStream { /// ```rust,ignore /// match expr { /// Ok(r) => r, -/// Err(e) => return ::mingling::Groupped::to_chain(e), +/// Err(e) => return ::mingling::Grouped::to_chain(e), /// } /// ``` /// /// It is useful inside chain functions where you have a `Result` -/// where both types implement `Groupped` and want to propagate the error case -/// as an early return via `Groupped::to_chain()`. +/// where both types implement `Grouped` and want to propagate the error case +/// as an early return via `Grouped::to_chain()`. /// /// # Example /// @@ -555,7 +555,7 @@ pub fn route(input: TokenStream) -> TokenStream { let expanded = quote! { match #expr { Ok(r) => r, - Err(e) => return ::mingling::Groupped::to_chain(e), + Err(e) => return ::mingling::Grouped::to_chain(e), } }; TokenStream::from(expanded) @@ -613,7 +613,7 @@ pub fn route(input: TokenStream) -> TokenStream { #[proc_macro] pub fn empty_result(_input: TokenStream) -> TokenStream { let expanded = quote! { - >::to_chain(crate::ResultEmpty) + >::to_chain(crate::ResultEmpty) }; TokenStream::from(expanded) } @@ -1250,10 +1250,10 @@ pub fn help(_attr: TokenStream, item: TokenStream) -> TokenStream { help::help_attr(item) } -/// Derive macro for automatically implementing the `Groupped` trait on a struct. +/// Derive macro for automatically implementing the `Grouped` trait on a struct. /// -/// The `#[derive(Groupped)]` macro: -/// 1. Implements `Groupped`. +/// The `#[derive(Grouped)]` macro: +/// 1. Implements `Grouped`. /// 2. Registers the type via `register_type!` so it's included in the program enum. /// 3. Generates `Into>` and `Into>` conversions. /// 4. Adds `to_chain()` and `to_render()` methods to the struct. @@ -1261,7 +1261,7 @@ pub fn help(_attr: TokenStream, item: TokenStream) -> TokenStream { /// # Syntax /// /// ```rust,ignore -/// #[derive(Groupped)] +/// #[derive(Grouped)] /// struct MyStruct { /// // ... /// } @@ -1270,9 +1270,9 @@ pub fn help(_attr: TokenStream, item: TokenStream) -> TokenStream { /// # Example /// /// ```rust,ignore -/// use mingling::macros::Groupped; +/// use mingling::macros::Grouped; /// -/// #[derive(Groupped)] +/// #[derive(Grouped)] /// struct Greeting { /// name: String, /// } @@ -1280,9 +1280,9 @@ pub fn help(_attr: TokenStream, item: TokenStream) -> TokenStream { /// /// This is equivalent to using `pack!` but works with custom structs that /// have named fields. For simple wrappers, prefer `pack!`. -#[proc_macro_derive(Groupped, attributes(group))] -pub fn derive_groupped(input: TokenStream) -> TokenStream { - groupped::derive_groupped(input) +#[proc_macro_derive(Grouped, attributes(group))] +pub fn derive_grouped(input: TokenStream) -> TokenStream { + grouped::derive_grouped(input) } /// Derive macro for automatically implementing the `EnumTag` trait on an enum @@ -1351,18 +1351,18 @@ pub fn derive_structural_data(input: TokenStream) -> TokenStream { structural_data::derive_structural_data(input) } -/// Derive macro for implementing both `Groupped` and `serde::Serialize` on a struct. +/// Derive macro for implementing both `Grouped` and `serde::Serialize` on a struct. /// /// **This macro is only available with the `structural_renderer` feature.** /// -/// This is identical to `#[derive(Groupped)]` but also adds `#[derive(serde::Serialize)]` +/// This is identical to `#[derive(Grouped)]` but also adds `#[derive(serde::Serialize)]` /// to the struct, which is required for the structural renderer to serialize output /// to formats like JSON, YAML, TOML, or RON. /// /// # Syntax /// /// ```rust,ignore -/// #[derive(GrouppedSerialize)] +/// #[derive(GroupedSerialize)] /// struct Info { /// name: String, /// age: i32, @@ -1372,19 +1372,19 @@ pub fn derive_structural_data(input: TokenStream) -> TokenStream { /// # Example /// /// ```rust,ignore -/// use mingling::GrouppedSerialize; +/// use mingling::GroupedSerialize; /// use serde::Serialize; /// -/// #[derive(GrouppedSerialize)] +/// #[derive(GroupedSerialize)] /// struct Info { /// name: String, /// age: i32, /// } /// ``` #[cfg(feature = "structural_renderer")] -#[proc_macro_derive(GrouppedSerialize, attributes(group))] -pub fn derive_groupped_serialize(input: TokenStream) -> TokenStream { - groupped::derive_groupped_serialize(input) +#[proc_macro_derive(GroupedSerialize, attributes(group))] +pub fn derive_grouped_serialize(input: TokenStream) -> TokenStream { + grouped::derive_grouped_serialize(input) } /// Generates the program enum and all collected types, chains, and renderers. @@ -1474,7 +1474,7 @@ pub fn program_comp_gen(_input: TokenStream) -> TokenStream { #[doc(hidden)] #[::mingling::macros::chain] pub async fn __exec_completion(prev: CompletionContext) -> Next { - use ::mingling::Groupped; + use ::mingling::Grouped; let read_ctx = ::mingling::ShellContext::try_from(prev.inner); match read_ctx { @@ -1492,7 +1492,7 @@ pub fn program_comp_gen(_input: TokenStream) -> TokenStream { #[doc(hidden)] #[::mingling::macros::chain] pub fn __exec_completion(prev: CompletionContext) -> Next { - use ::mingling::Groupped; + use ::mingling::Grouped; let read_ctx = ::mingling::ShellContext::try_from(prev.inner); match read_ctx { @@ -1516,7 +1516,7 @@ pub fn program_comp_gen(_input: TokenStream) -> TokenStream { let comp_dispatcher = quote! { #[doc(hidden)] mod __internal_completion_mod { - use ::mingling::Groupped; + use ::mingling::Grouped; ::mingling::macros::dispatcher!("__comp", CMDCompletion => CompletionContext); ::mingling::macros::pack!( CompletionSuggest = (::mingling::ShellContext, ::mingling::Suggest) @@ -1548,7 +1548,7 @@ pub fn program_comp_gen(_input: TokenStream) -> TokenStream { /// Registers a type into the global packed types registry for inclusion in /// the program enum generated by `gen_program!`. /// -/// This macro is called internally by `pack!` and `#[derive(Groupped)]`(`macro.derive_groupped.html`) +/// This macro is called internally by `pack!` and `#[derive(Grouped)]`(`macro.derive_grouped.html`) /// and is generally not needed in user code. However, it can be used for manual /// registration if you are implementing custom type registration outside of /// the standard macros. @@ -1653,13 +1653,13 @@ pub fn register_renderer(input: TokenStream) -> TokenStream { pub fn program_fallback_gen(_input: TokenStream) -> TokenStream { #[cfg(feature = "structural_renderer")] let pack_empty = quote! { - #[derive(::serde::Serialize, ::mingling::StructuralData, ::mingling::Groupped, Default)] + #[derive(::serde::Serialize, ::mingling::StructuralData, ::mingling::Grouped, Default)] pub struct ResultEmpty; }; #[cfg(not(feature = "structural_renderer"))] let pack_empty = quote! { - #[derive(::mingling::Groupped, Default)] + #[derive(::mingling::Grouped, Default)] pub struct ResultEmpty; }; @@ -1675,7 +1675,7 @@ pub fn program_fallback_gen(_input: TokenStream) -> TokenStream { /// and its `ProgramCollect` implementation. /// /// This is the core code generation macro that: -/// 1. Collects all registered types (from `pack!`, `#[derive(Groupped)]`, etc.) and +/// 1. Collects all registered types (from `pack!`, `#[derive(Grouped)]`, etc.) and /// creates an enum with each type as a variant. /// 2. Generates the `Display` implementation for the enum. /// 3. Generates the `ProgramCollect` implementation that dispatches to all diff --git a/mingling_macros/src/pack.rs b/mingling_macros/src/pack.rs index 7f05232..0af1b4c 100644 --- a/mingling_macros/src/pack.rs +++ b/mingling_macros/src/pack.rs @@ -138,7 +138,7 @@ pub fn pack(input: TokenStream) -> TokenStream { } } - impl ::mingling::Groupped<#group_name> for #type_name { + impl ::mingling::Grouped<#group_name> for #type_name { fn member_id() -> #group_name { #group_name::#type_name } diff --git a/mingling_macros/src/pack_err.rs b/mingling_macros/src/pack_err.rs index ba7cf17..a747aa9 100644 --- a/mingling_macros/src/pack_err.rs +++ b/mingling_macros/src/pack_err.rs @@ -42,7 +42,7 @@ pub fn pack_err(input: TokenStream) -> TokenStream { // Note: No longer derives Serialize under structural_renderer. // Use pack_err_structural for structured output support. let derive = quote! { - #[derive(::mingling::Groupped)] + #[derive(::mingling::Grouped)] }; let expanded = quote! { @@ -75,7 +75,7 @@ pub fn pack_err(input: TokenStream) -> TokenStream { // Note: No longer derives Serialize under structural_renderer. // Use pack_err_structural for structured output support. let derive = quote! { - #[derive(::mingling::Groupped)] + #[derive(::mingling::Grouped)] }; let expanded = quote! { @@ -150,7 +150,7 @@ pub fn pack_err_structural(input: TokenStream) -> TokenStream { let snake_name = snake_case!(&name_str); let expanded = quote! { - #[derive(::mingling::Groupped, ::serde::Serialize)] + #[derive(::mingling::Grouped, ::serde::Serialize)] pub struct #type_name { /// The snake_case name of this error, automatically set at compile time. pub name: String, @@ -179,7 +179,7 @@ pub fn pack_err_structural(input: TokenStream) -> TokenStream { let snake_name = snake_case!(&name_str); let expanded = quote! { - #[derive(::mingling::Groupped, ::serde::Serialize)] + #[derive(::mingling::Grouped, ::serde::Serialize)] pub struct #type_name { /// The snake_case name of this error, automatically set at compile time. pub name: String, diff --git a/mingling_macros/src/structural_data.rs b/mingling_macros/src/structural_data.rs index 5350d7e..74bcf09 100644 --- a/mingling_macros/src/structural_data.rs +++ b/mingling_macros/src/structural_data.rs @@ -176,7 +176,7 @@ pub(crate) fn pack_structural(input: TokenStream) -> TokenStream { } } - impl ::mingling::Groupped<#program_path> for #type_name { + impl ::mingling::Grouped<#program_path> for #type_name { fn member_id() -> #program_path { #program_path::#type_name } @@ -297,7 +297,7 @@ pub(crate) fn group_structural(input: TokenStream) -> TokenStream { #type_use #alias_use - impl ::mingling::Groupped<__MinglingProgram> for #type_name { + impl ::mingling::Grouped<__MinglingProgram> for #type_name { fn member_id() -> __MinglingProgram { __MinglingProgram::#type_name } -- cgit