From 57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 05:49:19 +0800 Subject: refactor!: replace pack! macros with derive-based pipeline types Remove the `pack!`, `pack_err!`, `pack_structural!`, and `pack_err_structural!` macros, replacing all pipeline type definitions with `#[derive(Grouped)]` and `#[derive(Grouped, Wrap)]` attributes. This changes the generated struct shape from named-field structs with an `inner` field to tuple structs accessed via `.0`, and removes the auto-generated `name` and `info` fields from error types. --- mingling_macros/src/func/pack_err.rs | 108 ----------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 mingling_macros/src/func/pack_err.rs (limited to 'mingling_macros/src/func/pack_err.rs') diff --git a/mingling_macros/src/func/pack_err.rs b/mingling_macros/src/func/pack_err.rs deleted file mode 100644 index e925b82..0000000 --- a/mingling_macros/src/func/pack_err.rs +++ /dev/null @@ -1,108 +0,0 @@ -// Doc Not Optimize -use just_fmt::snake_case; -use proc_macro::TokenStream; -use quote::quote; -use syn::{Ident, Token, Type, parse_macro_input}; - -enum PackErrInput { - /// `pack_err!(ErrorNotFound)` - Simple { type_name: Ident }, - /// `pack_err!(ErrorNotDir = PathBuf)` - Typed { - type_name: Ident, - inner_type: Box, - }, -} - -impl syn::parse::Parse for PackErrInput { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let type_name: Ident = input.parse()?; - - if input.peek(Token![=]) { - input.parse::()?; - let inner_type: Type = input.parse()?; - Ok(Self::Typed { - type_name, - inner_type: Box::new(inner_type), - }) - } else { - Ok(Self::Simple { type_name }) - } - } -} - -#[allow(clippy::too_many_lines)] -pub(crate) fn pack_err(input: TokenStream) -> TokenStream { - let parsed = parse_macro_input!(input as PackErrInput); - - match parsed { - PackErrInput::Simple { type_name } => { - let name_str = type_name.to_string(); - let snake_name = snake_case!(&name_str); - - // Note: No longer derives Serialize under structural_renderer. - // Use pack_err_structural for structured output support. - let derive = quote! { - #[derive(::mingling::Grouped)] - }; - - let expanded = quote! { - #derive - pub struct #type_name { - /// The snake_case name of this error, automatically set at compile time. - pub name: String, - } - - impl ::std::default::Default for #type_name { - fn default() -> Self { - Self { - name: #snake_name.into(), - } - } - } - - ::mingling::macros::register_type!(#type_name); - }; - - expanded.into() - } - PackErrInput::Typed { - type_name, - inner_type, - } => { - let name_str = type_name.to_string(); - let snake_name = snake_case!(&name_str); - - // Note: No longer derives Serialize under structural_renderer. - // Use pack_err_structural for structured output support. - let derive = quote! { - #[derive(::mingling::Grouped)] - }; - - let expanded = quote! { - #derive - pub struct #type_name { - /// The snake_case name of this error, automatically set at compile time. - pub name: String, - /// Additional context info for this error. - pub info: #inner_type, - } - - impl #type_name { - /// Creates a new error with the given info. - /// The `name` field is automatically set to the snake_case of the struct name. - pub fn new(info: #inner_type) -> Self { - Self { - name: #snake_name.into(), - info, - } - } - } - - ::mingling::macros::register_type!(#type_name); - }; - - expanded.into() - } - } -} -- cgit