aboutsummaryrefslogtreecommitdiff
path: root/docs/pages
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-28 09:13:12 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-28 09:13:12 +0800
commit7610a6f53f835995b06c9c623fbca1d188f07544 (patch)
tree32e2eb2f56aea2e037d93d76676741da96e78230 /docs/pages
parent2c32196bbc632411d4f6998a506ca262a805a666 (diff)
Simplify Picker API by removing generic parameter and route types
Diffstat (limited to 'docs/pages')
-rw-r--r--docs/pages/3-features/1-parser.md60
1 files changed, 30 insertions, 30 deletions
diff --git a/docs/pages/3-features/1-parser.md b/docs/pages/3-features/1-parser.md
index b3c7a05..0b5ded5 100644
--- a/docs/pages/3-features/1-parser.md
+++ b/docs/pages/3-features/1-parser.md
@@ -276,38 +276,38 @@ pack!(MinGreaterThanMax = ());
fn parse_fruit_eat(prev: FruitEatEntry) -> NextProcess {
let picker = Picker::new(prev.inner);
let mut min_weight: i16 = 0;
- let parsed = picker
- .pick_or(["--count", "-n"], 1)
- .pick::<i16>("--min-weight") // default: 0
- .after(|min| {
- // Copy `min` to external variable
- min_weight = min;
- min
- })
- .pick_or::<i16>("--max-weight", min_weight) // default: min_weight
- .after_or_route(|max| {
- // Check if `max` is valid
- if max < &min_weight {
- Err(MinGreaterThanMax::default())
- } else {
- Ok(max.clone())
- }
- })
- .pick(())
- .unpack();
-
- match parsed {
- Ok((count, min_weight, max_weight, fruit_type)) => {
- let parsed = ParsedEatFruit {
- count,
- weight_range: (min_weight, max_weight),
- fruit_type,
- };
+ let (count, min_weight, max_weight, fruit_type) = route! {
+ picker
+ // Pick count
+ .pick_or::<i16>(["--count", "-n"], 1 as i16)
+
+ // Pick min/max weight
+ .pick::<i16>("--min-weight")
+ .after(|min| {
+ min_weight = min;
+ min
+ })
+
+ .pick_or::<i16>("--max-weight", min_weight)
+ .after_or_route(|max| {
+ if max < &min_weight {
+ Err(MinGreaterThanMax::default().to_render())
+ } else {
+ Ok(max.clone())
+ }
+ })
+
+ // Pick Type
+ .pick(())
+ .unpack()
+ };
- AnyOutput::new(parsed).route_renderer()
- }
- Err(route) => route.to_render(),
+ ParsedEatFruit {
+ count,
+ weight_range: (min_weight, max_weight),
+ fruit_type,
}
+ .to_render()
}
#[renderer]