diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-17 11:08:07 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-17 11:11:28 +0800 |
| commit | 79ec6878877f0fd9246d67d3cd4f8cc2d1200150 (patch) | |
| tree | e3cd8cfc7ef5cd2a6a7ceb93d9a4b1764fa21b61 /mingling_picker/src/pickable/single_pickable.rs | |
| parent | e6136f22cff446b16dbebf3b26a6fdea6dbc0e83 (diff) | |
refactor: rename `mingling_picker` to `arg_picker`
Diffstat (limited to 'mingling_picker/src/pickable/single_pickable.rs')
| -rw-r--r-- | mingling_picker/src/pickable/single_pickable.rs | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/mingling_picker/src/pickable/single_pickable.rs b/mingling_picker/src/pickable/single_pickable.rs deleted file mode 100644 index 8a5b3e6..0000000 --- a/mingling_picker/src/pickable/single_pickable.rs +++ /dev/null @@ -1,69 +0,0 @@ -use crate::{Pickable, PickerArg, PickerArgAttr, PickerArgResult, TagPhaseContext}; - -/// `SinglePickable` trait defines how to parse a type from a single command-line argument. -/// -/// This trait provides a simplified interface for types that consume exactly one argument value. -/// It is automatically implemented by the blanket `impl` of [`Pickable`], so types implementing -/// `SinglePickable` will work with the full `Pickable` argument parsing system. -/// -/// Additionally, `Option<S>` where `S: SinglePickable` also implements [`Pickable`], allowing -/// optional arguments to be parsed naturally. -/// -/// # Type Parameters -/// -/// * `Self` - The type to be parsed from a single argument string. -pub trait SinglePickable -where - Self: Sized, -{ - /// Parse a single optional string value into an instance of `Self`. - /// - /// # Parameters - /// - /// * `str` - An `Option<&str>` representing the raw argument value. If `None`, - /// it indicates that no argument value was provided (e.g., for flag-like arguments). - /// - /// # Returns - /// - /// Returns [`PickerArgResult<Self>`], i.e., the parsed `Self` instance on success, - /// or an appropriate error message on failure. - fn pick_single(str: Option<&str>) -> PickerArgResult<Self>; -} - -impl<'a, S> Pickable<'a> for S -where - S: SinglePickable, -{ - fn get_attr(flag: &'a PickerArg<'a, Self>) -> PickerArgAttr { - PickerArgAttr::positional_or_single(flag) - } - - fn tag(ctx: TagPhaseContext) -> Vec<usize> { - crate::parselib::SingleMatcher::tag(ctx) - } - - fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> { - Self::pick_single(crate::parselib::seek_single(raw_strs)) - } -} - -impl<'a, S> Pickable<'a> for Option<S> -where - S: SinglePickable, -{ - fn get_attr(flag: &'a PickerArg<'a, Self>) -> PickerArgAttr { - PickerArgAttr::positional_or_single(flag) - } - - fn tag(ctx: TagPhaseContext) -> Vec<usize> { - crate::parselib::SingleMatcher::tag(ctx) - } - - fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> { - match S::pick(raw_strs) { - PickerArgResult::Unparsed => PickerArgResult::Unparsed, - PickerArgResult::Parsed(r) => PickerArgResult::Parsed(Some(r)), - PickerArgResult::NotFound => PickerArgResult::Parsed(None), - } - } -} |
