aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/func/pack_err_structural.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
commit57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d (patch)
tree1cd4aef44cb7a45a8cd9d520b598f5f181e24c76 /mingling_macros/src/func/pack_err_structural.rs
parentef23cd944402939605c78a4a853ef6e33af02c21 (diff)
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.
Diffstat (limited to 'mingling_macros/src/func/pack_err_structural.rs')
-rw-r--r--mingling_macros/src/func/pack_err_structural.rs121
1 files changed, 0 insertions, 121 deletions
diff --git a/mingling_macros/src/func/pack_err_structural.rs b/mingling_macros/src/func/pack_err_structural.rs
deleted file mode 100644
index 950b8dc..0000000
--- a/mingling_macros/src/func/pack_err_structural.rs
+++ /dev/null
@@ -1,121 +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};
-
-/// `pack_err_structural!` — like `pack_err!` but also marks the type as
-/// supporting structured output via `StructuralData`.
-pub(crate) fn pack_err_structural(input: TokenStream) -> TokenStream {
- let parsed = parse_macro_input!(input as PackErrInput);
-
- let type_name = match &parsed {
- PackErrInput::Simple { type_name } | PackErrInput::Typed { type_name, .. } => {
- type_name.clone()
- }
- };
-
- // Register in STRUCTURED_TYPES
- let type_name_str = type_name.to_string();
- crate::get_global_set(&crate::STRUCTURED_TYPES)
- .lock()
- .unwrap()
- .insert(type_name_str);
-
- let structural_data = quote! {
- impl ::mingling::__private::StructuralDataSealed<crate::ThisProgram> for #type_name {}
- impl ::mingling::__private::StructuralData<crate::ThisProgram> for #type_name {}
- };
-
- // Generate the struct + impls (same as pack_err! but with Serialize derive + sealed)
- match parsed {
- PackErrInput::Simple { type_name } => {
- let name_str = type_name.to_string();
- let snake_name = snake_case!(&name_str);
-
- let expanded = quote! {
- #[derive(::mingling::Grouped, ::serde::Serialize)]
- 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);
-
- #structural_data
- };
-
- expanded.into()
- }
- PackErrInput::Typed {
- type_name,
- inner_type,
- } => {
- let name_str = type_name.to_string();
- let snake_name = snake_case!(&name_str);
-
- let expanded = quote! {
- #[derive(::mingling::Grouped, ::serde::Serialize)]
- 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);
-
- #structural_data
- };
-
- expanded.into()
- }
- }
-}
-
-// Re-use pack_err's input parser
-enum PackErrInput {
- Simple {
- type_name: Ident,
- },
- Typed {
- type_name: Ident,
- inner_type: Box<Type>,
- },
-}
-
-impl syn::parse::Parse for PackErrInput {
- fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
- let type_name: Ident = input.parse()?;
-
- if input.peek(Token![=]) {
- input.parse::<Token![=]>()?;
- let inner_type: Type = input.parse()?;
- Ok(Self::Typed {
- type_name,
- inner_type: Box::new(inner_type),
- })
- } else {
- Ok(Self::Simple { type_name })
- }
- }
-}