From 5e460470f6ea2ce31a403b6e936ec2fe8f45312a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 19 Jul 2026 00:22:23 +0800 Subject: feat: migrate mingling-specific picker code into mingling crate BREAKING CHANGE: Remove `mingling_support` feature from arg-picker crate. The `EntryPicker` trait and `corebind` module are now part of the mingling crate directly, and `build_pattern1` is now a public method. --- arg_picker/src/corebind/entry_picker.rs | 131 -------------------------------- arg_picker/src/lib.rs | 14 +--- arg_picker/src/picker.rs | 14 +++- 3 files changed, 12 insertions(+), 147 deletions(-) delete mode 100644 arg_picker/src/corebind/entry_picker.rs (limited to 'arg_picker/src') diff --git a/arg_picker/src/corebind/entry_picker.rs b/arg_picker/src/corebind/entry_picker.rs deleted file mode 100644 index d543f98..0000000 --- a/arg_picker/src/corebind/entry_picker.rs +++ /dev/null @@ -1,131 +0,0 @@ -use std::marker::PhantomData; - -use mingling_core::{ChainProcess, Groupped, ProgramCollect}; - -use crate::{Pickable, Picker, PickerArg, 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::macros::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); - Picker::build_pattern1(picker.args, arg.into(), None) - } - - /// Starts building a picker pattern with the first argument, using a default value provider. - /// - /// This is a shorthand for calling `.pick(arg).or(func)`. - /// - /// # Type Parameters - /// - /// * `Next` — The nominal type of the first argument; must implement [`Pickable`]. - /// - /// # Parameters - /// - /// * `arg` — The argument definition, typically obtained from [`crate::macros::arg`]. - /// * `func` — A closure that provides a default value if the arg is not provided by the user. - fn pick_or( - self, - arg: impl Into<&'a PickerArg<'a, Next>>, - func: F, - ) -> PickerPattern1<'a, Next, ChainProcess> - where - Self: Sized, - Next: Pickable<'a> + Default + Sized, - F: FnMut() -> Next + 'static, - { - self.pick(arg).or(func) - } - - /// Starts building a picker pattern with the first argument, using a default value. - /// - /// This is a shorthand for calling `.pick(arg).or_default()`. - /// - /// # Type Parameters - /// - /// * `Next` — The nominal type of the first argument; must implement [`Pickable`] and [`Default`]. - /// - /// # Parameters - /// - /// * `arg` — The argument definition, typically obtained from [`crate::macros::arg`]. - fn pick_or_default( - self, - arg: impl Into<&'a PickerArg<'a, Next>>, - ) -> PickerPattern1<'a, Next, ChainProcess> - where - Self: Sized, - Next: Pickable<'a> + Default + Sized, - { - self.pick(arg).or_default() - } - - /// Starts building a picker pattern with the first argument, using a route if the arg is not provided. - /// - /// This is a shorthand for calling `.pick(arg).or_route(func)`. - /// - /// # Type Parameters - /// - /// * `Next` — The nominal type of the first argument; must implement [`Pickable`]. - /// - /// # Parameters - /// - /// * `arg` — The argument definition, typically obtained from [`crate::macros::arg`]. - /// * `func` — A closure that produces a route value if the arg is not provided by the user. - fn pick_or_route( - self, - arg: impl Into<&'a PickerArg<'a, Next>>, - func: F, - ) -> PickerPattern1<'a, Next, ChainProcess> - where - Self: Sized, - Next: Pickable<'a> + Default + Sized, - F: FnMut() -> ChainProcess + 'static, - { - self.pick(arg).or_route(func) - } -} - -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), - } - } -} diff --git a/arg_picker/src/lib.rs b/arg_picker/src/lib.rs index 21a0d35..c65e793 100644 --- a/arg_picker/src/lib.rs +++ b/arg_picker/src/lib.rs @@ -29,13 +29,8 @@ pub mod value; /// use arg_picker::prelude::*; /// ``` pub mod prelude { - pub use crate::macros::arg; - - #[cfg(not(feature = "mingling_support"))] pub use crate::IntoPicker; - - #[cfg(feature = "mingling_support")] - pub use crate::corebind::EntryPicker; + pub use crate::macros::arg; } /// Re-export of the `arg_picker_macros` crate @@ -53,10 +48,3 @@ pub mod matcher_needed { pub use crate::PickerArgInfo; pub use crate::parselib::{MaskedArg, Matcher, ParserStyle}; } - -#[cfg(feature = "mingling_support")] -mod corebind; - -#[allow(unused_imports)] -#[cfg(feature = "mingling_support")] -pub use corebind::*; diff --git a/arg_picker/src/picker.rs b/arg_picker/src/picker.rs index 7a60e16..f31a5b6 100644 --- a/arg_picker/src/picker.rs +++ b/arg_picker/src/picker.rs @@ -158,6 +158,15 @@ impl<'a> IntoIterator for &'a PickerArgs<'a> { } } +impl<'a, Route> From> for Picker<'a, Route> { + fn from(args: PickerArgs<'a>) -> Self { + Picker { + route_phantom: PhantomData, + args, + } + } +} + impl<'a, Route> From<&'a [&'a str]> for Picker<'a, Route> { fn from(value: &'a [&'a str]) -> Self { Picker { @@ -428,10 +437,9 @@ impl<'a> IntoPicker<'a> for Vec { } } -// Private helper: shared construction logic for `PickerPattern1`. -// Both `Picker::pick` and `IntoPicker::pick` delegate to this. impl<'a, Route> Picker<'a, Route> { - pub(crate) fn build_pattern1( + /// Build the PickerPattern via Arguments + pub fn build_pattern1( args: PickerArgs<'a>, arg: &'a PickerArg<'a, N>, error_route: Option, -- cgit