From c3e990a5c47dc8894899d774a0d89f089adec308 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 15 Jul 2026 16:08:10 +0800 Subject: refactor: rename `PickerResult` to `PickerArgResult` and add new `PickerResult` struct --- mingling_picker/src/picker/patterns.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'mingling_picker/src/picker/patterns.rs') diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs index 4f54f9d..b828849 100644 --- a/mingling_picker/src/picker/patterns.rs +++ b/mingling_picker/src/picker/patterns.rs @@ -1,6 +1,6 @@ use mingling_picker_macros::internal_repeat; -use crate::{Pickable, Picker, PickerArgs, PickerFlag, PickerResult}; +use crate::{Pickable, Picker, PickerArgResult, PickerArgs, PickerFlag}; internal_repeat!(1..=32 => { #[doc(hidden)] @@ -10,7 +10,7 @@ internal_repeat!(1..=32 => { pub args: PickerArgs<'a>, ( pub flag_$: &'a PickerFlag<'a, T$>, - pub result_$: PickerResult, + pub result_$: PickerArgResult, pub default_$: Option T$>>, pub post_$: Option T$>>, +) @@ -43,6 +43,27 @@ internal_repeat!(1..=32 => { self } + /// Uses the default value for this flag's type if the flag is not provided. + /// + /// If the flag is not provided by the user at runtime, the default value for `T$` + /// (as defined by the `Default` trait) will be used. + /// + /// # Example + /// + /// ```ignore + /// let pattern = picker + /// .pick(&my_flag) + /// .or_default(); + /// ``` + #[allow(clippy::type_complexity)] + pub fn or_default(mut self) -> Self + where + T$: Default, + { + self.default_$ = Some(Box::new(|| T$::default())); + self + } + /// Attaches a post-processing function to this flag. /// /// After the flag's value is parsed (or defaulted), the given closure will be @@ -88,7 +109,7 @@ internal_repeat!(1..32 => { // Current flag_$+: flag, - result_$+: PickerResult::Unparsed, + result_$+: PickerArgResult::Unparsed, default_$+: None, post_$+: None, @@ -116,7 +137,7 @@ impl<'a> Picker<'a> { PickerPattern1 { args: self.args, flag_1: flag, - result_1: PickerResult::Unparsed, + result_1: PickerArgResult::Unparsed, default_1: None, post_1: None, } -- cgit