diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-20 07:36:03 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-20 07:36:03 +0800 |
| commit | a6697111573952903b3d9d0659ffe1af23432c3c (patch) | |
| tree | 9490fd96d1581e3d2954e2ca4894014ad5d29f00 /arg_picker_macros | |
| parent | cdc1864344003321ffae7fe597465d02fd3a5865 (diff) | |
feat: add pick_or, pick_or_default, and pick_or_route shorthands
Remove the `Default` bound from `pick()` and `EntryPicker::pick()`,
allowing non-Default types to be used as arguments.
Add `IntoPicker::pick_or`, `pick_or_default`, and `pick_or_route`
convenience methods for common fallback patterns.
Fix token splitting in `arg!` macro to correctly handle angle brackets.
Diffstat (limited to 'arg_picker_macros')
| -rw-r--r-- | arg_picker_macros/src/arg.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/arg_picker_macros/src/arg.rs b/arg_picker_macros/src/arg.rs index 55860c4..20731b1 100644 --- a/arg_picker_macros/src/arg.rs +++ b/arg_picker_macros/src/arg.rs @@ -119,6 +119,7 @@ pub(crate) fn arg(input: TokenStream) -> TokenStream { fn split_at_commas(tokens: &[TokenTree]) -> Vec<Vec<TokenTree>> { let mut result = vec![Vec::new()]; let mut depth = 0u32; + let mut angle_depth = 0u32; for t in tokens { match t { TokenTree::Group(_g) => { @@ -126,7 +127,15 @@ fn split_at_commas(tokens: &[TokenTree]) -> Vec<Vec<TokenTree>> { result.last_mut().unwrap().push(t.clone()); depth -= 1; } - TokenTree::Punct(p) if p.as_char() == ',' && depth == 0 => { + TokenTree::Punct(p) if p.as_char() == '<' => { + angle_depth += 1; + result.last_mut().unwrap().push(t.clone()); + } + TokenTree::Punct(p) if p.as_char() == '>' && angle_depth > 0 => { + angle_depth -= 1; + result.last_mut().unwrap().push(t.clone()); + } + TokenTree::Punct(p) if p.as_char() == ',' && depth == 0 && angle_depth == 0 => { result.push(Vec::new()); } _ => result.last_mut().unwrap().push(t.clone()), |
