aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/src/requirement.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 02:17:33 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 02:17:33 +0800
commitde370df01a171b4fd910dfa9a067830acd1f9a3c (patch)
tree53350a4cdaa93437da6f06916ac371f82e79c57b /mingling_picker/src/requirement.rs
parent62f6b476284da67efc55483a81b57f99a478702a (diff)
refactor(mingling_picker): move parse result out of requirement and into
pattern BREAKING CHANGE: `PickerRequirement` no longer stores a `PickerResult`. Parsed results are now held in the `PickerPattern` structs. The `result`, `result_mut`, `set_result`, `reset_result`, and `with_result` methods on `PickerRequirement` have been removed. The `Picker::pick` method is introduced to begin a pattern definition.
Diffstat (limited to 'mingling_picker/src/requirement.rs')
-rw-r--r--mingling_picker/src/requirement.rs48
1 files changed, 10 insertions, 38 deletions
diff --git a/mingling_picker/src/requirement.rs b/mingling_picker/src/requirement.rs
index 32fefff..564ae45 100644
--- a/mingling_picker/src/requirement.rs
+++ b/mingling_picker/src/requirement.rs
@@ -1,4 +1,5 @@
-use crate::{Pickable, PickerResult};
+use crate::Pickable;
+use std::marker::PhantomData;
/// Represents a constraint definition for a parameter selection.
///
@@ -19,25 +20,23 @@ use crate::{Pickable, PickerResult};
/// than by a `--name` or `-n` flag.
/// - `false`: The parameter is a named (flag-based) parameter.
///
-/// - `result`: The parsed result of this parameter requirement. Initially set to
-/// `PickerResult::Unparsed`. After parsing, contains either the successfully parsed value or an
-/// error.
-#[derive(Default)]
+/// - `_type`: PhantomData to hold the type parameter.
+#[derive(Default, Clone, Copy)]
pub struct PickerRequirement<'a, Type>
where
Type: Default + Pickable,
{
/// Full name, may include variant names (aliases), e.g., `["config", "cfg"]`.
- full: &'a [&'a str],
+ pub full: &'a [&'a str],
/// Short name, e.g., `'c'`.
- short: Option<char>,
+ pub short: Option<char>,
/// Whether the parameter is positional (no flag, matched by position).
- positional: bool,
+ pub positional: bool,
- /// The parsed result of this parameter requirement.
- result: PickerResult<Type>,
+ /// PhantomData to hold the type parameter.
+ pub internal_type: PhantomData<Type>,
}
impl<'a, Type> PickerRequirement<'a, Type>
@@ -50,7 +49,7 @@ where
full,
short,
positional,
- result: PickerResult::Unparsed,
+ internal_type: PhantomData,
}
}
@@ -120,31 +119,4 @@ where
self.positional = positional;
self
}
-
- /// Returns a reference to the current parse result.
- pub fn result(&self) -> &PickerResult<Type> {
- &self.result
- }
-
- /// Returns a mutable reference to the current parse result.
- pub fn result_mut(&mut self) -> &mut PickerResult<Type> {
- &mut self.result
- }
-
- /// Sets the parse result.
- pub fn set_result(&mut self, result: PickerResult<Type>) {
- self.result = result;
- }
-
- /// Replaces the parse result with `PickerResult::Unparsed` and returns self.
- pub fn reset_result(mut self) -> Self {
- self.result = PickerResult::Unparsed;
- self
- }
-
- /// Sets the parse result and returns self.
- pub fn with_result(mut self, result: PickerResult<Type>) -> Self {
- self.result = result;
- self
- }
}