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
use super::{ErrorKind, ParseDirection, ParseError, Parser};
impl<'a> Parser<'a> {
#[inline]
pub const fn from_bytes(bytes: &'a [u8]) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: 0,
bytes,
}
}
#[inline]
pub const fn from_str(string: &'a str) -> Self {
Self {
parse_direction: ParseDirection::FromStart,
start_offset: 0,
bytes: string.as_bytes(),
}
}
#[inline(always)]
pub const fn bytes(self) -> &'a [u8] {
self.bytes
}
#[inline(always)]
pub const fn start_offset(self) -> usize {
self.start_offset as _
}
#[inline(always)]
pub const fn end_offset(self) -> usize {
self.start_offset as usize + self.bytes.len()
}
pub fn parse_direction(&self) -> ParseDirection {
self.parse_direction
}
pub const fn into_error(self, kind: ErrorKind) -> ParseError<'a> {
ParseError::new(self, kind)
}
pub const fn into_other_error(self) -> ParseError<'a> {
ParseError::new(self, ErrorKind::Other)
}
pub const fn advance_to_remainder_from_start(mut self, to: &'a [u8]) -> Self {
parsing! {self, FromStart;
self.bytes = to;
}
}
pub const fn advance_to_remainder_from_end(mut self, to: &'a [u8]) -> Self {
parsing! {self, FromEnd;
self.bytes = to;
}
}
#[inline(always)]
pub const fn len(self) -> usize {
self.bytes.len()
}
#[inline(always)]
pub const fn is_empty(self) -> bool {
self.bytes.is_empty()
}
}