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
/// Parses a type that impls [`HasParser`] with the passed in [`Parser`].
///
/// # Example
///
/// This example demonstrates how you can use this macro to parse both
/// standard library and user-defined types.
///
/// ```rust
/// use konst::{result, try_};
///
/// use konst::parsing::{HasParser, Parser, ParseError, parse_type};
///
/// const PAIR: (u32, Foo) = result::unwrap!(parse_pair(&mut Parser::new("100,Baz")));
///
/// assert_eq!(PAIR.0, 100);
/// assert_eq!(PAIR.1, Foo::Baz);
///
/// const fn parse_pair<'p>(parser: &mut Parser<'p>) -> Result<(u32, Foo), ParseError<'p>> {
/// let left = try_!(parse_type!(parser, u32));
/// _ = parser.strip_prefix(',');
/// let right = try_!(parse_type!(parser, Foo));
///
/// Ok((left, right))
/// }
///
///
/// #[derive(Debug, PartialEq)]
/// enum Foo {
/// Bar,
/// Baz,
/// Qux,
/// }
///
/// impl HasParser for Foo {
/// type Parser = Self;
/// }
///
/// impl Foo {
/// const fn parse_with<'p>(parser: &mut Parser<'p>) -> Result<Self, ParseError<'p>> {
/// // You can use the `parser_method` macro instead of this chain of if elses
/// if parser.strip_prefix("Bar").is_ok() {
/// Ok(Foo::Bar)
/// } else if parser.strip_prefix("Baz").is_ok() {
/// Ok(Foo::Baz)
/// } else if parser.strip_prefix("Qux").is_ok() {
/// Ok(Foo::Qux)
/// } else {
/// Err(parser.to_other_error(&"expected one of `Bar`, `Baz`, or `Qux`"))
/// }
/// }
/// }
/// ```
///
/// [`Parser`]: crate::parsing::Parser
/// [`HasParser`]: crate::parsing::HasParser
pub use crate__parse_type as parse_type;