aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 03:26:28 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 03:26:28 +0800
commit3480d26c10f09f886de47f7f31096b4bc1303a41 (patch)
tree46454b61123e72b359bc39190d484fa0af2ae501
parent132b065e53e53b588a496d8649bd60872ab88a5c (diff)
feat(picker): add `pick` method to start and extend flag chains
-rw-r--r--mingling_picker/src/picker.rs18
-rw-r--r--mingling_picker/src/picker/patterns.rs9
2 files changed, 27 insertions, 0 deletions
diff --git a/mingling_picker/src/picker.rs b/mingling_picker/src/picker.rs
index ecf59b0..914d8b2 100644
--- a/mingling_picker/src/picker.rs
+++ b/mingling_picker/src/picker.rs
@@ -3,6 +3,8 @@ use std::ops::Index;
mod patterns;
pub use patterns::*;
+use crate::{Pickable, PickerFlag, PickerResult};
+
/// Picker, used to record all states of a parameter parsing
///
/// Includes the following:
@@ -222,6 +224,22 @@ pub trait IntoPicker<'a> {
/// assert_eq!(args.len(), 2);
/// ```
fn to_picker(self) -> Picker<'a>;
+
+ /// Creates a `PickerPattern1` from the given flag for the `pick` method.
+ ///
+ /// This method converts the value into a `Picker` and starts a parameter
+ /// picking chain with one flag. The result is initially `Unparsed`.
+ fn pick<N>(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern1<'a, N>
+ where
+ Self: Sized,
+ N: Pickable + Default + Sized,
+ {
+ PickerPattern1 {
+ args: self.to_picker().args,
+ flag_1: flag,
+ result_1: PickerResult::Unparsed,
+ }
+ }
}
impl<'a> IntoPicker<'a> for &'a [&'a str] {
diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs
index 2242a70..2501823 100644
--- a/mingling_picker/src/picker/patterns.rs
+++ b/mingling_picker/src/picker/patterns.rs
@@ -19,6 +19,11 @@ internal_repeat!(1..32 => {
where (T$: Pickable + Default,+)
{
#[allow(clippy::type_complexity)]
+ /// Adds a new flag to the picking chain, returning a new `PickerPattern` with one more type parameter.
+ ///
+ /// This method extends the current picking pattern by appending an additional flag.
+ /// The previous flags and their results are preserved as part of the new pattern.
+ /// The new flag's result is initially `Unparsed`.
pub fn pick<N>(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern$+<'a, (T$,+), N>
where
N: Pickable + Default,
@@ -42,6 +47,10 @@ internal_repeat!(1..32 => {
});
impl<'a> Picker<'a> {
+ /// Creates a `PickerPattern1` from the given flag to start a picking chain.
+ ///
+ /// This method initiates a parameter picking chain with one flag.
+ /// The result is initially `Unparsed`.
pub fn pick<N>(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern1<'a, N>
where
N: Pickable + Default,