diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-15 20:30:40 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-15 20:30:40 +0800 |
| commit | 75f420f8d50910888822c412724ff80fbce32ac5 (patch) | |
| tree | 8741cf52f16fffae221e19897d82c013cd399643 /mingling_picker/src/picker | |
| parent | 406e7232ab1d0f7d64be4843afbcf2f9b3984104 (diff) | |
feat(picker): remove route phantom from IntoPicker trait
Add `with_route` methods to `IntoPicker` and `PickerPattern` for
setting the route type explicitly when needed, instead of carrying
it as a generic parameter on the trait itself.
Diffstat (limited to 'mingling_picker/src/picker')
| -rw-r--r-- | mingling_picker/src/picker/patterns.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs index 1b21d32..20faadd 100644 --- a/mingling_picker/src/picker/patterns.rs +++ b/mingling_picker/src/picker/patterns.rs @@ -87,6 +87,32 @@ internal_repeat!(1..=32 => { self } + + /// Resets the route for this picker pattern, allowing a different route type. + /// + /// This method converts the current `PickerPattern` into a new one with a different + /// route type `NewRoute`. All existing flag configurations, defaults, and post- + /// processing functions are preserved, but the `error_route` and individual + /// `route_$` fields are cleared (set to `None`). + /// + /// This is useful when you want to change the error/redirect route type mid-chain, + /// for example when composing patterns from different contexts that use different + /// route enums. + #[allow(clippy::type_complexity)] + pub fn with_route<NewRoute>(self) -> PickerPattern$<'a, (T$,+), NewRoute> { + PickerPattern$ { + args: self.args, + error_route: None, + ( + flag_$: self.flag_$, + result_$: self.result_$, + default_$: self.default_$, + route_$: None, + post_$: self.post_$, + +) + } + } + /// Attaches a post-processing function to this flag. /// /// After the flag's value is parsed (or defaulted), the given closure will be |
