aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/picker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'arg_picker/src/picker.rs')
-rw-r--r--arg_picker/src/picker.rs74
1 files changed, 73 insertions, 1 deletions
diff --git a/arg_picker/src/picker.rs b/arg_picker/src/picker.rs
index f31a5b6..f722fb5 100644
--- a/arg_picker/src/picker.rs
+++ b/arg_picker/src/picker.rs
@@ -369,11 +369,83 @@ pub trait IntoPicker<'a> {
fn pick<N>(self, arg: impl Into<&'a PickerArg<'a, N>>) -> PickerPattern1<'a, N, ()>
where
Self: Sized,
- N: Pickable<'a> + Default + Sized,
+ N: Pickable<'a> + Sized,
{
Picker::build_pattern1(self.to_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<Next, F>(
+ self,
+ arg: impl Into<&'a PickerArg<'a, Next>>,
+ func: F,
+ ) -> PickerPattern1<'a, Next, ()>
+ where
+ Self: Sized,
+ Next: Pickable<'a> + 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<Next>(
+ self,
+ arg: impl Into<&'a PickerArg<'a, Next>>,
+ ) -> PickerPattern1<'a, Next, ()>
+ 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<Next, F, Route>(
+ self,
+ arg: impl Into<&'a PickerArg<'a, Next>>,
+ func: F,
+ ) -> PickerPattern1<'a, Next, Route>
+ where
+ Self: Sized,
+ Next: Pickable<'a> + Sized,
+ F: FnMut() -> Route + 'static,
+ {
+ self.pick(arg).with_route::<Route>().or_route(func)
+ }
+
/// Converts the value into a `Picker` with a specified route type.
///
/// This method allows changing the route (phantom type parameter) of the picker.