aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/src/pickable.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 19:43:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 19:51:19 +0800
commitfdd26053228593162fd5c41df9cfbc45d0c731b9 (patch)
treec8782756a80d8fadf681ead52b4e512d4a1b2a9d /mingling_picker/src/pickable.rs
parent538516a2104edba2c35b1f4ce40ec5a25589b62b (diff)
feat: add lifetime-bound pickable support and refine type constraints
Diffstat (limited to 'mingling_picker/src/pickable.rs')
-rw-r--r--mingling_picker/src/pickable.rs22
1 files changed, 15 insertions, 7 deletions
diff --git a/mingling_picker/src/pickable.rs b/mingling_picker/src/pickable.rs
index 9fe2c9d..7a89631 100644
--- a/mingling_picker/src/pickable.rs
+++ b/mingling_picker/src/pickable.rs
@@ -1,4 +1,4 @@
-use crate::PickerResult;
+use crate::{PickerFlag, PickerResult, PickerTag};
mod implements;
@@ -20,20 +20,28 @@ mod implements;
/// # Examples
///
/// ```
-/// # use mingling_picker::{Pickable, PickerResult};
+/// # use mingling_picker::{Pickable, PickerResult, PickerFlag, PickerTag};
/// #[derive(Default)]
/// struct MyType(String);
///
-/// impl Pickable for MyType {
-/// fn pick(raw_str: &str) -> PickerResult<Self> {
-/// PickerResult::Parsed(MyType(raw_str.to_string()))
+/// impl<'a> Pickable<'a> for MyType {
+/// fn tag(flag: &'a PickerFlag<'a, Self>) -> PickerTag<'a> {
+/// let tag = PickerTag::from(flag);
+/// }
+///
+/// fn pick(raw_strs: &[&str]) -> PickerResult<Self> {
+/// PickerResult::Parsed(MyType(raw_strs.join(" ")))
/// }
/// }
/// ```
-pub trait Pickable
+pub trait Pickable<'a>
where
Self: Sized + Default,
{
+ /// Given a [`PickerFlag`], returns a [`PickerTag`] that tells the parser
+ /// about the argument's characteristics (e.g., positional, optional, multi).
+ fn tag(flag: &'a PickerFlag<'a, Self>) -> PickerTag<'a>;
+
/// Parses a `Self` value from the given raw string input.
- fn pick(raw_str: &str) -> PickerResult<Self>;
+ fn pick(raw_strs: &[&str]) -> PickerResult<Self>;
}