aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker_macros/src/req.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 02:17:33 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 02:17:33 +0800
commitde370df01a171b4fd910dfa9a067830acd1f9a3c (patch)
tree53350a4cdaa93437da6f06916ac371f82e79c57b /mingling_picker_macros/src/req.rs
parent62f6b476284da67efc55483a81b57f99a478702a (diff)
refactor(mingling_picker): move parse result out of requirement and into
pattern BREAKING CHANGE: `PickerRequirement` no longer stores a `PickerResult`. Parsed results are now held in the `PickerPattern` structs. The `result`, `result_mut`, `set_result`, `reset_result`, and `with_result` methods on `PickerRequirement` have been removed. The `Picker::pick` method is introduced to begin a pattern definition.
Diffstat (limited to 'mingling_picker_macros/src/req.rs')
-rw-r--r--mingling_picker_macros/src/req.rs63
1 files changed, 32 insertions, 31 deletions
diff --git a/mingling_picker_macros/src/req.rs b/mingling_picker_macros/src/req.rs
index 1c3bb99..35c9027 100644
--- a/mingling_picker_macros/src/req.rs
+++ b/mingling_picker_macros/src/req.rs
@@ -68,50 +68,51 @@ pub(crate) fn req(input: TokenStream) -> TokenStream {
None => aliases,
};
- // Generate code
- let import = quote! { ::mingling::picker::PickerRequirement };
-
- // Type parameter
- let ty_ts: TS2 = ty
- .map(|t| {
- let ts: TokenStream = t.iter().cloned().collect();
- ts.to_string().parse().unwrap()
- })
- .unwrap_or(TS2::new());
-
- let with_type = if ty.is_some() {
- quote! { #import::<#ty_ts> }
- } else {
- quote! { #import::<_> }
+ let path: TS2 = {
+ let ty_ts: TS2 = ty
+ .map(|t| {
+ let ts: TokenStream = t.iter().cloned().collect();
+ ts.to_string().parse().unwrap()
+ })
+ .unwrap_or(TS2::new());
+
+ let import = quote! { ::mingling::picker::PickerRequirement };
+ if ty.is_some() {
+ quote! { #import::<#ty_ts> }
+ } else {
+ quote! { #import::<_> }
+ }
};
- // .with_full(...)
- let with_full = if !full_names.is_empty() {
+ // full: &["name", "alias", ...] or &[]
+ let full_value: TS2 = if !full_names.is_empty() {
let strs: Vec<proc_macro2::Literal> = full_names
.iter()
.map(|s| proc_macro2::Literal::string(s))
.collect();
- quote! { .with_full(&[#(#strs),*]) }
+ quote! { &[#(#strs),*] }
} else {
- TS2::new()
+ quote! { &[] }
};
- // .with_short(...)
- let with_short = short_char
- .map(|c| {
+ // short: Some('c') or None
+ let short_value: TS2 = match short_char {
+ Some(c) => {
let lit = proc_macro2::Literal::character(c);
- quote! { .with_short(#lit) }
- })
- .unwrap_or_default();
+ quote! { ::std::option::Option::Some(#lit) }
+ }
+ None => quote! { ::std::option::Option::None },
+ };
- // .with_positional(...)
- let pos = !is_named;
+ let positional_value: bool = !is_named;
let result = quote! {
- #with_type::default()
- #with_full
- #with_short
- .with_positional(#pos)
+ #path {
+ full: #full_value,
+ short: #short_value,
+ positional: #positional_value,
+ internal_type: ::std::marker::PhantomData,
+ }
};
result.into()