diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-14 01:36:27 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-14 01:36:27 +0800 |
| commit | 4665fc94ab9508d115298dd988e2381354f46c01 (patch) | |
| tree | a2b14f5684c68d88a0a77570d0ac3ac8d863867b /mingling_picker/src/pickable.rs | |
| parent | 5ac0f0e98d05e95f7e3c58995f8d79670cbac772 (diff) | |
feat(picker): add core trait, types, and builder macro for argument
parsing
Implement the foundational `mingling_picker` library along with its
companion
`mingling_picker_macros` crate. The picker provides:
- `Pickable` trait for parsing types from raw strings
- `PickerResult` enum modeling parse outcomes
- `Picker` struct for storing and indexing command-line arguments
- `PickerRequirement` struct for declarative parameter definitions
- `PickerPattern` family (1..32) of typed pattern structs via the
`internal_repeat` proc macro
- `req!` proc macro as a succinct builder for `PickerRequirement`
Re-export `mingling_picker::macros::*` from the `mingling` crate when
the
`picker` feature is enabled, replacing the previous wildcard re-export
of
`mingling_macros`.
Diffstat (limited to 'mingling_picker/src/pickable.rs')
| -rw-r--r-- | mingling_picker/src/pickable.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mingling_picker/src/pickable.rs b/mingling_picker/src/pickable.rs new file mode 100644 index 0000000..9fe2c9d --- /dev/null +++ b/mingling_picker/src/pickable.rs @@ -0,0 +1,39 @@ +use crate::PickerResult; + +mod implements; + +/// A trait for types that can be constructed from a raw string representation. +/// +/// Implementing this trait allows a type to be "picked" or parsed from a string, +/// enabling deserialization or configuration loading from textual input. +/// +/// # Requirements +/// +/// - The implementing type must be [`Sized`] and implement [`Default`]. +/// - The [`pick`] method performs the actual parsing and may fail. +/// +/// # Errors +/// +/// Returns a [`PickerResult`] which encapsulates either a successful parse +/// or an error indicating why the input could not be parsed. +/// +/// # Examples +/// +/// ``` +/// # use mingling_picker::{Pickable, PickerResult}; +/// #[derive(Default)] +/// struct MyType(String); +/// +/// impl Pickable for MyType { +/// fn pick(raw_str: &str) -> PickerResult<Self> { +/// PickerResult::Parsed(MyType(raw_str.to_string())) +/// } +/// } +/// ``` +pub trait Pickable +where + Self: Sized + Default, +{ + /// Parses a `Self` value from the given raw string input. + fn pick(raw_str: &str) -> PickerResult<Self>; +} |
