From 80c66d1efc9babfc1991edc023b06adad680edbb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 17 Jul 2026 08:48:29 +0800 Subject: feat(picker): expose internal fields and add `IntoPicker` for `&Vec` Make `route_phantom` and `args` fields `pub(crate)` for internal reuse. Fix error route conversion by adding `.into()` call. Implement `IntoPicker` for `&Vec` to support passing string references. --- mingling_picker/src/picker.rs | 14 ++++++++++++-- mingling_picker/src/picker/parse.rs | 2 +- mingling_picker/src/picker/patterns.rs | 13 +++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) (limited to 'mingling_picker/src') diff --git a/mingling_picker/src/picker.rs b/mingling_picker/src/picker.rs index 69b1671..81fb10a 100644 --- a/mingling_picker/src/picker.rs +++ b/mingling_picker/src/picker.rs @@ -12,10 +12,10 @@ use crate::{Pickable, PickerArg, PickerArgResult}; #[doc = include_str!("../README.md")] pub struct Picker<'a, Route = ()> { - route_phantom: PhantomData, + pub(crate) route_phantom: PhantomData, /// Internal arguments of Picker - args: PickerArgs<'a>, + pub(crate) args: PickerArgs<'a>, } impl<'a> Picker<'a> { @@ -344,6 +344,16 @@ impl<'a> IntoPicker<'a> for Vec<&'a str> { } } +impl<'a> IntoPicker<'a> for &'a Vec { + fn to_picker(self) -> Picker<'a, ()> { + let slice: Vec<&str> = self.iter().map(|s| s.as_str()).collect(); + Picker { + route_phantom: PhantomData, + args: PickerArgs::Vec(slice), + } + } +} + impl<'a> IntoPicker<'a> for Vec { fn to_picker(self) -> Picker<'a, ()> { Picker { diff --git a/mingling_picker/src/picker/parse.rs b/mingling_picker/src/picker/parse.rs index 8f7d514..698baac 100644 --- a/mingling_picker/src/picker/parse.rs +++ b/mingling_picker/src/picker/parse.rs @@ -124,7 +124,7 @@ internal_repeat!(1..=32 => { } else { if error_route.is_none() { if let Some(get_route) = self.route_$ { - *error_route = Some(get_route()); + *error_route = Some(get_route().into()); } } other diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs index 3c6e73f..daaf43a 100644 --- a/mingling_picker/src/picker/patterns.rs +++ b/mingling_picker/src/picker/patterns.rs @@ -10,11 +10,11 @@ internal_repeat!(1..=32 => { pub args: PickerArgs<'a>, pub error_route: Option, ( - pub arg_$: &'a PickerArg<'a, T$>, - pub result_$: PickerArgResult, - pub default_$: Option T$>>, - pub route_$: Option Route>>, - pub post_$: Option T$>>, + pub(crate) arg_$: &'a PickerArg<'a, T$>, + pub(crate) result_$: PickerArgResult, + pub(crate) default_$: Option T$>>, + pub(crate) route_$: Option Route>>, + pub(crate) post_$: Option T$>>, +) } }); @@ -99,7 +99,8 @@ internal_repeat!(1..=32 => { /// for example when composing patterns from different contexts that use different /// route enums. #[allow(clippy::type_complexity)] - pub fn with_route(self) -> PickerPattern$<'a, (T$,+), NewRoute> { + pub fn with_route(self) -> PickerPattern$<'a, (T$,+), NewRoute> + { PickerPattern$ { args: self.args, error_route: None, -- cgit