aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/pickable.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-20 08:51:43 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-20 08:51:43 +0800
commitff1e3262641529468841c531795df0fed8b08350 (patch)
tree540d64a0ee9d9443999322b125dfade0b716b480 /arg_picker/src/pickable.rs
parent4a4591affcdb9fef4025e1493546ea77132ce7d2 (diff)
feat!: extract arg-picker into standalone repositoryHEADmain
Diffstat (limited to 'arg_picker/src/pickable.rs')
-rw-r--r--arg_picker/src/pickable.rs92
1 files changed, 0 insertions, 92 deletions
diff --git a/arg_picker/src/pickable.rs b/arg_picker/src/pickable.rs
deleted file mode 100644
index 014bbc2..0000000
--- a/arg_picker/src/pickable.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-// Doc Not Optimize
-use crate::{PickerArg, PickerArgAttr, PickerArgInfo, PickerArgResult, PickerArgs};
-
-mod single_pickable;
-pub use single_pickable::*;
-
-mod multi_pickable;
-pub use multi_pickable::*;
-
-/// `Pickable` trait defines how to parse a type instance from command-line arguments.
-///
-/// This trait is the core abstraction of the `Picker` argument parsing system, dividing the
-/// parsing process into two phases:
-///
-/// 1. **Tag phase ([`Pickable::tag`])**: Determines which argument positions the `Pickable` needs to handle.
-/// 2. **Pick phase ([`Pickable::pick`])**: Converts the raw strings at the tagged positions into the actual type.
-///
-/// Types implementing this trait must also implement [`Default`], so that a default value
-/// can be used as a fallback when parsing fails.
-///
-/// # Type Parameters
-///
-/// * `'a` - Lifetime parameter, used to associate references in [`PickerArg`].
-pub trait Pickable<'a>
-where
- Self: Sized,
-{
- /// Returns the parse-order attribute of this flag.
- ///
- /// This attribute is used to inform the parser about the parse order
- /// between different `Pickable` types.
- /// See [`PickerArgAttr`] for specific ordering definitions.
- ///
- /// # Parameters
- ///
- /// * `flag` - The current flag instance, which contains a reference to `Self`.
- ///
- /// # Returns
- ///
- /// Returns a [`PickerArgAttr`] describing the parse-order attribute of this flag.
- fn get_attr(flag: &'a PickerArg<'a, Self>) -> PickerArgAttr;
-
- /// Tag phase: Determines which argument positions the `Pickable` needs to handle.
- ///
- /// This function receives a [`TagPhaseContext`] containing argument context information.
- /// During this phase, the parser invokes each `Pickable` and collects the position indices
- /// they return, in order to determine which arguments to parse later.
- ///
- /// # Parameters
- ///
- /// * `ctx` - The tag phase context, containing argument information, all parameters of the
- /// current Picker, and an availability mask.
- ///
- /// # Returns
- ///
- /// Returns a `Vec<usize>` representing the indices of the arguments in the argument list
- /// that this `Pickable` needs to handle.
- fn tag(ctx: TagPhaseContext) -> Vec<usize>;
-
- /// Pick phase: Converts the raw string arguments tagged during the `tag` phase into
- /// the actual expected type.
- ///
- /// This function receives a slice of the raw strings that were tagged in the `tag` step
- /// and converts them into an instance of `Self`.
- ///
- /// # Parameters
- ///
- /// * `raw_strs` - A slice of strings containing the raw argument values to parse.
- ///
- /// # Returns
- ///
- /// Returns [`PickerArgResult<Self>`], i.e., the `Self` instance on success, or an appropriate
- /// error message on failure.
- fn pick(raw_strs: &[&str]) -> PickerArgResult<Self>;
-}
-
-/// Tag phase context, providing the necessary argument and state information for
-/// [`Pickable::tag`].
-pub struct TagPhaseContext<'a> {
- /// Argument information describing the structure and metadata of the argument
- /// to be parsed.
- pub arg_info: &'a PickerArgInfo<'a>,
-
- /// A read-only list of all arguments in the current [`Picker`](crate::Picker).
- pub args: &'a PickerArgs<'a>,
-
- /// Mask indicating which argument positions have already been claimed.
- ///
- /// For example, if the mask is `[0, 0, 1, 0]`, then the argument at index `2`
- /// has already been tagged by another `Pickable`.
- pub mask: &'a [u8],
-}