aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/entry.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-20 00:59:17 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-20 01:01:27 +0800
commit1f583f625a7d541dc7d47a8136b31d29a5ed5441 (patch)
tree795006c8c2a9f10c866951de5aba318a64007219 /mingling_macros/src/entry.rs
parente8ae63988d562969df47ae6d92129974e7fb6980 (diff)
chore(macros): reorganize module hierarchy in mingling_macros
Restructure flat module layout into logical directories (attr/, derive/, func/, systems/, extensions/, utils.rs). Tighten internal function visibility to pub(crate). All public API signatures remain unchanged.
Diffstat (limited to 'mingling_macros/src/entry.rs')
-rw-r--r--mingling_macros/src/entry.rs70
1 files changed, 0 insertions, 70 deletions
diff --git a/mingling_macros/src/entry.rs b/mingling_macros/src/entry.rs
deleted file mode 100644
index 2ac5d6b..0000000
--- a/mingling_macros/src/entry.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-use proc_macro::TokenStream;
-use quote::quote;
-use syn::{Ident, LitStr, parse_macro_input};
-
-enum EntryInput {
- Typed { ident: Ident, strings: Vec<String> },
- Untyped { strings: Vec<String> },
-}
-
-impl syn::parse::Parse for EntryInput {
- fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
- // entry!(EntryType, ["a", "b", "c"])
- // entry!["a", "b", "c"] — comes in as just ["a", "b", "c"]
- if input.peek(Ident) && input.peek2(syn::Token![,]) {
- // entry!(EntryType, ["a", "b", "c"])
- let ident: Ident = input.parse()?;
- let _comma: syn::Token![,] = input.parse()?;
- let content;
- syn::bracketed!(content in input);
- let strings = parse_strings(&content)?;
- Ok(EntryInput::Typed { ident, strings })
- } else {
- // entry!["a", "b", "c"] — bare bracket content
- let strings = parse_strings(input)?;
- Ok(EntryInput::Untyped { strings })
- }
- }
-}
-
-fn parse_strings(input: &syn::parse::ParseBuffer) -> syn::Result<Vec<String>> {
- let mut strings = Vec::new();
- while !input.is_empty() {
- let s: LitStr = input.parse()?;
- strings.push(s.value());
- if input.peek(syn::Token![,]) {
- let _comma: syn::Token![,] = input.parse()?;
- }
- }
- Ok(strings)
-}
-
-pub fn entry(input: TokenStream) -> TokenStream {
- let parsed = parse_macro_input!(input as EntryInput);
-
- let strings = match &parsed {
- EntryInput::Typed { strings, .. } | EntryInput::Untyped { strings } => strings,
- };
- let string_exprs = strings
- .iter()
- .map(|s| {
- let lit = syn::LitStr::new(s, proc_macro2::Span::call_site());
- quote! { #lit.to_string() }
- })
- .collect::<Vec<_>>();
-
- let expanded = match parsed {
- EntryInput::Typed { ident, .. } => {
- quote! {
- #ident::new(vec![#(#string_exprs),*])
- }
- }
- EntryInput::Untyped { .. } => {
- quote! {
- vec![#(#string_exprs),*].into()
- }
- }
- };
-
- expanded.into()
-}