From d77e8926dff6466f0c46ee4529dd9f7b9772ae99 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 17 Jul 2026 08:48:35 +0800 Subject: feat(corebind): add EntryPicker trait for binding entry types to Picker BREAKING CHANGE: prelude now exports EntryPicker in place of IntoPicker when mingling_support feature is enabled --- mingling_picker/src/corebind/entry_picker.rs | 67 ++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mingling_picker/src/corebind/entry_picker.rs (limited to 'mingling_picker/src/corebind/entry_picker.rs') diff --git a/mingling_picker/src/corebind/entry_picker.rs b/mingling_picker/src/corebind/entry_picker.rs new file mode 100644 index 0000000..f96ba66 --- /dev/null +++ b/mingling_picker/src/corebind/entry_picker.rs @@ -0,0 +1,67 @@ +use std::marker::PhantomData; + +use mingling_core::{ChainProcess, Groupped, ProgramCollect}; + +use crate::{Pickable, Picker, PickerArg, PickerArgResult, PickerArgs, PickerPattern1}; + +/// Trait for converting Mingling entry types (types that implement `Groupped` and `Into>`) +/// into [`Picker`] instances for a given route type `R`. +/// +/// This trait provides a bridge between entry definitions created with the `mingling` framework +/// and the picker argument system used for CLI argument parsing and routing. +/// +/// # Type Parameters +/// +/// * `'a` — The lifetime of the picker and its references to argument definitions. +/// * `This` — The program type used for dispatching runtime routes; must implement [`ProgramCollect`]. +/// * `Route` — The route type used for dispatching; must implement [`Groupped`]. +pub trait EntryPicker<'a, This> { + /// Converts `self` into a [`Picker`] for the given route type `Route`. + fn to_picker(self) -> Picker<'a, ChainProcess>; + + /// Starts building a picker pattern with the first argument. + /// + /// Returns a [`PickerPattern1`] that can be further chained with additional + /// arguments, defaults, routes, and post-processing. + /// + /// # Type Parameters + /// + /// * `Next` — The nominal type of the first argument; must implement [`Pickable`]. + /// + /// # Parameters + /// + /// * `arg` — The argument definition, typically obtained from [`crate::arg`]. + fn pick( + self, + arg: impl Into<&'a PickerArg<'a, Next>>, + ) -> PickerPattern1<'a, Next, ChainProcess> + where + Self: Sized, + Next: Pickable<'a> + Default + Sized, + { + let picker = Self::to_picker(self); + PickerPattern1 { + args: picker.args, + arg_1: arg.into(), + result_1: PickerArgResult::Unparsed, + default_1: None, + route_1: None, + post_1: None, + error_route: None, + } + } +} + +impl<'a, This, Bind> EntryPicker<'a, This> for Bind +where + This: ProgramCollect, + Bind: Groupped + Into>, +{ + fn to_picker(self) -> Picker<'a, ChainProcess> { + let args = self.into(); + Picker { + route_phantom: PhantomData, + args: PickerArgs::Owned(args), + } + } +} -- cgit