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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use crate;
use PhantomData;
/// Gets a type that parses `Self` with a `parse_with` method.
///
/// Implementing this trait allows parsing a type with the [`parse_with`] macro.
///
/// # Implementing this trait
///
/// You can implement this trait like this:
/// ```rust
/// # struct SomeType;
/// # struct SomeParser;
/// # use konst::parsing::ParserFor;
/// impl ParserFor for SomeType {
/// // This is usually `Self` for user-defined types.
/// type Parser = SomeParser;
/// }
/// ```
/// Then `SomeParser` is expected to have a `parse_with` associated function with this signature:
/// ```rust
/// # /*
/// impl SomeParser {
/// const fn parse_with<'a>(
/// _: konst::Parser<'a>
/// ) -> Result<(This, konst::Parser<'a>), SomeErrorType>
/// }
/// # */
/// ```
///
/// # Example
///
/// ```rust
/// use konst::{parse_with, try_rebind, unwrap_ctx};
///
/// use konst::parsing::{ParserFor, Parser, ParseValueResult};
///
/// const PAIR: Pair = {
/// let parser = Parser::from_str("100,200");
/// unwrap_ctx!(parse_with!(parser, Pair)).0
/// };
///
/// assert_eq!(PAIR, Pair(100, 200));
///
///
/// #[derive(Debug, PartialEq)]
/// struct Pair(u32, u64);
///
/// impl ParserFor for Pair {
/// type Parser = Self;
/// }
///
/// impl Pair {
/// const fn parse_with(mut parser: Parser<'_>) -> ParseValueResult<'_, Self> {
/// try_rebind!{(let left, parser) = parse_with!(parser, u32)}
/// try_rebind!{parser = parser.strip_prefix_u8(b',')}
/// try_rebind!{(let right, parser) = parse_with!(parser, u64)}
///
/// Ok((Pair(left, right), parser))
/// }
/// }
/// ```
///
/// [`parse_with`]: ../macro.parse_with.html
/// [`ParserFor::Parser`]: #associatedtype.Parser
///
////////////////////////////////////////////////////////////////////////////////
/// Parses a standard library type, determined by the `StdType` type parameter.
///
///
///
;
impl_std_parser!