aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/func
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-10 16:19:45 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-10 16:19:45 +0800
commit2d0aae4b2d595ced100f7a2ec8d13b872a5eb65e (patch)
tree9df306e1185470655f3ed43fad866cf02430160f /mingling_macros/src/func
parent61b770ca958afa7e5eca4c50f5e06bdf3ed7a94a (diff)
refactor: simplify macro parsing code and fix clippy warnings
Diffstat (limited to 'mingling_macros/src/func')
-rw-r--r--mingling_macros/src/func/dispatcher.rs2
-rw-r--r--mingling_macros/src/func/entry.rs4
-rw-r--r--mingling_macros/src/func/group.rs4
-rw-r--r--mingling_macros/src/func/group_structural.rs4
-rw-r--r--mingling_macros/src/func/pack_err.rs8
-rw-r--r--mingling_macros/src/func/pack_err_structural.rs9
6 files changed, 16 insertions, 15 deletions
diff --git a/mingling_macros/src/func/dispatcher.rs b/mingling_macros/src/func/dispatcher.rs
index d834c95..bbe1074 100644
--- a/mingling_macros/src/func/dispatcher.rs
+++ b/mingling_macros/src/func/dispatcher.rs
@@ -32,7 +32,7 @@ impl Parse for DispatcherChainInput {
if input.is_empty() {
#[cfg(feature = "extras")]
{
- return Ok(DispatcherChainInput::Auto {
+ return Ok(Self::Auto {
cmd_attrs,
command_name,
});
diff --git a/mingling_macros/src/func/entry.rs b/mingling_macros/src/func/entry.rs
index 35209e5..76fbc15 100644
--- a/mingling_macros/src/func/entry.rs
+++ b/mingling_macros/src/func/entry.rs
@@ -18,11 +18,11 @@ impl syn::parse::Parse for EntryInput {
let content;
syn::bracketed!(content in input);
let strings = parse_strings(&content)?;
- Ok(EntryInput::Typed { ident, strings })
+ Ok(Self::Typed { ident, strings })
} else {
// entry!["a", "b", "c"] — bare bracket content
let strings = parse_strings(input)?;
- Ok(EntryInput::Untyped { strings })
+ Ok(Self::Untyped { strings })
}
}
}
diff --git a/mingling_macros/src/func/group.rs b/mingling_macros/src/func/group.rs
index edb1fe1..8ca46d9 100644
--- a/mingling_macros/src/func/group.rs
+++ b/mingling_macros/src/func/group.rs
@@ -33,10 +33,10 @@ impl Parse for GroupInput {
let alias: Ident = input.parse()?;
let _eq: syn::Token![=] = input.parse()?;
let type_path: TypePath = input.parse()?;
- Ok(GroupInput::Aliased { alias, type_path })
+ Ok(Self::Aliased { alias, type_path })
} else {
let type_path: TypePath = input.parse()?;
- Ok(GroupInput::Plain(type_path))
+ Ok(Self::Plain(type_path))
}
}
}
diff --git a/mingling_macros/src/func/group_structural.rs b/mingling_macros/src/func/group_structural.rs
index 2bd2f83..3e6dbc5 100644
--- a/mingling_macros/src/func/group_structural.rs
+++ b/mingling_macros/src/func/group_structural.rs
@@ -115,10 +115,10 @@ impl syn::parse::Parse for GroupStructuralInput {
let alias: Ident = input.parse()?;
let _eq: syn::Token![=] = input.parse()?;
let type_path: TypePath = input.parse()?;
- Ok(GroupStructuralInput::Aliased { alias, type_path })
+ Ok(Self::Aliased { alias, type_path })
} else {
let type_path: TypePath = input.parse()?;
- Ok(GroupStructuralInput::Plain(type_path))
+ Ok(Self::Plain(type_path))
}
}
}
diff --git a/mingling_macros/src/func/pack_err.rs b/mingling_macros/src/func/pack_err.rs
index 8b224b0..dcfcf86 100644
--- a/mingling_macros/src/func/pack_err.rs
+++ b/mingling_macros/src/func/pack_err.rs
@@ -4,9 +4,9 @@ use quote::quote;
use syn::{Ident, Token, Type, parse_macro_input};
enum PackErrInput {
- /// pack_err!(ErrorNotFound)
+ /// `pack_err!(ErrorNotFound)`
Simple { type_name: Ident },
- /// pack_err!(ErrorNotDir = PathBuf)
+ /// `pack_err!(ErrorNotDir = PathBuf)`
Typed {
type_name: Ident,
inner_type: Box<Type>,
@@ -20,12 +20,12 @@ impl syn::parse::Parse for PackErrInput {
if input.peek(Token![=]) {
input.parse::<Token![=]>()?;
let inner_type: Type = input.parse()?;
- Ok(PackErrInput::Typed {
+ Ok(Self::Typed {
type_name,
inner_type: Box::new(inner_type),
})
} else {
- Ok(PackErrInput::Simple { type_name })
+ Ok(Self::Simple { type_name })
}
}
}
diff --git a/mingling_macros/src/func/pack_err_structural.rs b/mingling_macros/src/func/pack_err_structural.rs
index 7d3a6f8..2c4a2fb 100644
--- a/mingling_macros/src/func/pack_err_structural.rs
+++ b/mingling_macros/src/func/pack_err_structural.rs
@@ -9,8 +9,9 @@ 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 } => type_name.clone(),
- PackErrInput::Typed { type_name, .. } => type_name.clone(),
+ PackErrInput::Simple { type_name } | PackErrInput::Typed { type_name, .. } => {
+ type_name.clone()
+ }
};
// Register in STRUCTURED_TYPES
@@ -108,12 +109,12 @@ impl syn::parse::Parse for PackErrInput {
if input.peek(Token![=]) {
input.parse::<Token![=]>()?;
let inner_type: Type = input.parse()?;
- Ok(PackErrInput::Typed {
+ Ok(Self::Typed {
type_name,
inner_type: Box::new(inner_type),
})
} else {
- Ok(PackErrInput::Simple { type_name })
+ Ok(Self::Simple { type_name })
}
}
}