blob: 9fe2c9de58117af19f2808bda46f16a20d4c926c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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>;
}
|