summaryrefslogtreecommitdiff
path: root/mingling/src/parser/picker.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-01 20:33:17 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-01 20:33:17 +0800
commitdddbd59ae526f5d2c86446c20095bd4fba6f6b94 (patch)
tree9d8232c1508886dff0b3df3404f6986095c13f2f /mingling/src/parser/picker.rs
parent7785c514137d99b1584d7b158015587a18f76525 (diff)
Add documentation for public items in lib and parser modules
Diffstat (limited to 'mingling/src/parser/picker.rs')
-rw-r--r--mingling/src/parser/picker.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/mingling/src/parser/picker.rs b/mingling/src/parser/picker.rs
index 9fcb3e6..7a0f211 100644
--- a/mingling/src/parser/picker.rs
+++ b/mingling/src/parser/picker.rs
@@ -1,17 +1,28 @@
use crate::parser::Argument;
use mingling_core::Flag;
+#[doc(hidden)]
pub mod builtin;
+/// A builder for extracting values from command-line arguments.
+///
+/// The `Picker` struct holds parsed arguments and provides a fluent interface
+/// to extract values associated with specific flags.
pub struct Picker {
+ /// The parsed command-line arguments.
pub args: Argument,
}
impl Picker {
+ /// Creates a new `Picker` from a value that can be converted into `Argument`.
pub fn new(args: impl Into<Argument>) -> Picker {
Picker { args: args.into() }
}
+ /// Extracts a value for the given flag and returns a `Pick1` builder.
+ ///
+ /// The extracted type `TNext` must implement `Pickable` and `Default`.
+ /// If the flag is not present, the default value for `TNext` is used.
pub fn pick<TNext>(mut self, val: impl Into<Flag>) -> Pick1<TNext>
where
TNext: Pickable<Output = TNext> + Default,
@@ -30,8 +41,17 @@ impl<T: Into<Argument>> From<T> for Picker {
}
}
+/// Extracts values from command-line arguments
+///
+/// The `Pickable` trait defines how to extract the value of a specific flag from parsed arguments
pub trait Pickable {
+ /// The output type produced by the extraction operation, must implement the `Default` trait
type Output: Default;
+
+ /// Extracts the value associated with the given flag from the provided arguments
+ ///
+ /// If the flag exists and the value can be successfully extracted, returns `Some(Output)`;
+ /// otherwise returns `None`
fn pick(args: &mut Argument, flag: Flag) -> Option<Self::Output>;
}
@@ -61,6 +81,7 @@ macro_rules! define_pick_structs {
where
$($T: Pickable,)+
{
+ /// Unpacks into the corresponding tuple
pub fn unpack(self) -> ($($T,)+) {
($(self.$val,)+)
}
@@ -75,6 +96,7 @@ macro_rules! impl_pick_structs {
where
$($T: Pickable,)+
{
+ /// Extracts a value for the given flag and returns a `PickN` builder.
pub fn pick<TNext>(mut self, val: impl Into<mingling_core::Flag>) -> $next<$($T,)+ TNext>
where
TNext: Pickable<Output = TNext> + Default,