aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/src/corebind/entry_picker.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-17 11:08:07 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-17 11:11:28 +0800
commit79ec6878877f0fd9246d67d3cd4f8cc2d1200150 (patch)
treee3cd8cfc7ef5cd2a6a7ceb93d9a4b1764fa21b61 /mingling_picker/src/corebind/entry_picker.rs
parente6136f22cff446b16dbebf3b26a6fdea6dbc0e83 (diff)
refactor: rename `mingling_picker` to `arg_picker`
Diffstat (limited to 'mingling_picker/src/corebind/entry_picker.rs')
-rw-r--r--mingling_picker/src/corebind/entry_picker.rs131
1 files changed, 0 insertions, 131 deletions
diff --git a/mingling_picker/src/corebind/entry_picker.rs b/mingling_picker/src/corebind/entry_picker.rs
deleted file mode 100644
index 69bc4d8..0000000
--- a/mingling_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<R>` and `Into<Vec<String>>`)
-/// 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<This>`].
-pub trait EntryPicker<'a, This> {
- /// Converts `self` into a [`Picker`] for the given route type `Route`.
- fn to_picker(self) -> Picker<'a, ChainProcess<This>>;
-
- /// 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<Next>(
- self,
- arg: impl Into<&'a PickerArg<'a, Next>>,
- ) -> PickerPattern1<'a, Next, ChainProcess<This>>
- 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::arg`].
- /// * `func` — A closure that provides a default value if the arg is not provided by the user.
- fn pick_or<Next, F>(
- self,
- arg: impl Into<&'a PickerArg<'a, Next>>,
- func: F,
- ) -> PickerPattern1<'a, Next, ChainProcess<This>>
- 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::arg`].
- fn pick_or_default<Next>(
- self,
- arg: impl Into<&'a PickerArg<'a, Next>>,
- ) -> PickerPattern1<'a, Next, ChainProcess<This>>
- 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::arg`].
- /// * `func` — A closure that produces a route value if the arg is not provided by the user.
- fn pick_or_route<Next, F>(
- self,
- arg: impl Into<&'a PickerArg<'a, Next>>,
- func: F,
- ) -> PickerPattern1<'a, Next, ChainProcess<This>>
- where
- Self: Sized,
- Next: Pickable<'a> + Default + Sized,
- F: FnMut() -> ChainProcess<This> + 'static,
- {
- self.pick(arg).or_route(func)
- }
-}
-
-impl<'a, This, Bind> EntryPicker<'a, This> for Bind
-where
- This: ProgramCollect<Enum = This>,
- Bind: Groupped<This> + Into<Vec<String>>,
-{
- fn to_picker(self) -> Picker<'a, ChainProcess<This>> {
- let args = self.into();
- Picker {
- route_phantom: PhantomData,
- args: PickerArgs::Owned(args),
- }
- }
-}