diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-15 17:09:27 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-15 17:09:27 +0800 |
| commit | 06199a26474b1e53761ca6838014c4dc8d3488e2 (patch) | |
| tree | 0fd9cdfcc680aa22799d8a9eb51beaa10379ae36 /mingling_picker/src/picker/parse.rs | |
| parent | d1a6e9810b4f1555fb9852065af4c9df6ed463f0 (diff) | |
feat(picker): add unwrap, unpack, to_result, to_option on PickerPattern
Diffstat (limited to 'mingling_picker/src/picker/parse.rs')
| -rw-r--r-- | mingling_picker/src/picker/parse.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/mingling_picker/src/picker/parse.rs b/mingling_picker/src/picker/parse.rs index 67122a5..744254d 100644 --- a/mingling_picker/src/picker/parse.rs +++ b/mingling_picker/src/picker/parse.rs @@ -6,6 +6,9 @@ // // P.S. If there's a better way, please let me know. Thanks! // -------------------------------------------------------------------------------------------- +// +// Then, I must disable `clippy::type_complexity` — this guy is way too noisy. +#![allow(clippy::type_complexity)] use crate::{ Pickable, PickerArgInfo, PickerArgResult, PickerArgs, PickerFlagAttr, TagPhaseContext, @@ -19,9 +22,49 @@ internal_repeat!(1..=32 => { internal_repeat!(1..=32 => { impl<'a, (T$,+), Route> PickerPattern$<'a, (T$,+), Route> + where (T$: Pickable<'a>,+) { + /// Unwraps the result, panicking if a route was selected. + /// + /// # Panics + /// + /// Panics if a route was selected. + pub fn unwrap(self) -> ((T$,+)) { + let p = self.parse(); + ((p.v$.unwrap(),+)) + } + + /// Returns the individual option values without checking the route. + pub fn unpack(self) -> ((Option<T$>,+)) { + let p = self.parse(); + ((p.v$,+)) + } + + /// Converts to a `Result`, returning `Err(route)` if a route was selected, + /// or `Ok(values)` otherwise. + pub fn to_result(self) -> Result<((T$,+)), Route> { + let p = self.parse(); + if let Some(r) = p.route { + return Err(r); + } + Ok(p.unwrap()) + } + + /// Converts to an `Option`, returning `None` if a route was selected, + /// or `Some(values)` otherwise. + pub fn to_option(self) -> Option<((T$,+))> { + let p = self.parse(); + if p.route.is_some() { + return None; + } + Some(p.unwrap()) + } + } +}); + +internal_repeat!(1..=32 => { + impl<'a, (T$,+), Route> PickerPattern$<'a, (T$,+), Route> where (T$: Pickable<'a>,+) { - #[allow(clippy::type_complexity)] pub fn parse(mut self) -> PickerResult$<(T$,+), Route> { // ArgInfos let arg_infos: [PickerArgInfo; $] = [ |
