aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 16:56:34 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 16:56:34 +0800
commit561e35154e4d453fdc14a2664316c858323b0de7 (patch)
tree000c164c185142e42ab0a35bd534a50bfc5d14bb
parente630ae88cf57c3b4df77565ea1bc2460f4bfff86 (diff)
feat(picker): add default and post-processing hooks for flags
-rw-r--r--mingling_picker/src/picker.rs8
-rw-r--r--mingling_picker/src/picker/patterns.rs8
2 files changed, 16 insertions, 0 deletions
diff --git a/mingling_picker/src/picker.rs b/mingling_picker/src/picker.rs
index 17a872d..01c94a9 100644
--- a/mingling_picker/src/picker.rs
+++ b/mingling_picker/src/picker.rs
@@ -34,6 +34,12 @@ pub enum PickerArgs<'a> {
Owned(Vec<String>),
}
+impl<'a> Default for PickerArgs<'a> {
+ fn default() -> Self {
+ Self::Vec(vec![])
+ }
+}
+
impl<'a> From<&'a [&'a str]> for Picker<'a> {
fn from(value: &'a [&'a str]) -> Self {
Picker {
@@ -241,6 +247,8 @@ pub trait IntoPicker<'a> {
args: self.to_picker().args,
flag_1: flag,
result_1: PickerResult::Unparsed,
+ default_1: None,
+ post_1: None,
}
}
}
diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs
index 2501823..1a0bad7 100644
--- a/mingling_picker/src/picker/patterns.rs
+++ b/mingling_picker/src/picker/patterns.rs
@@ -10,6 +10,8 @@ internal_repeat!(1..=32 => {
(
pub flag_$: &'a PickerFlag<'a, T$>,
pub result_$: PickerResult<T$>,
+ pub default_$: Option<Box<dyn FnMut() -> T$>>,
+ pub post_$: Option<Box<dyn FnMut(T$) -> T$>>,
+)
}
});
@@ -35,11 +37,15 @@ internal_repeat!(1..32 => {
// Current
flag_$+: flag,
result_$+: PickerResult::Unparsed,
+ default_$+: None,
+ post_$+: None,
// Prev
(
flag_$: self.flag_$,
result_$: self.result_$,
+ default_$: self.default_$,
+ post_$: self.post_$,
+)
}
}
@@ -59,6 +65,8 @@ impl<'a> Picker<'a> {
args: self.args,
flag_1: flag,
result_1: PickerResult::Unparsed,
+ default_1: None,
+ post_1: None,
}
}
}