From fdd26053228593162fd5c41df9cfbc45d0c731b9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 14 Jul 2026 19:43:56 +0800 Subject: feat: add lifetime-bound pickable support and refine type constraints --- mingling_picker/src/pickable.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'mingling_picker/src/pickable.rs') 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 { -/// 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 { +/// 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; + fn pick(raw_strs: &[&str]) -> PickerResult; } -- cgit