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
use crate::{
ParseIterator,
recorder::Recorder
};
#[derive(Debug)]
pub struct Stop<'a, T> {
inner: &'a mut T
}
impl<'a, T> Stop<'a, T> {
pub(super) fn new(inner: &'a mut T) -> Self {
Self {inner}
}
}
impl<'s, 'a, T> ParseIterator<'s> for Stop<'a, T>
where T: ParseIterator<'s> {
type PointInTime = T::PointInTime;
fn slice(&self) -> &'s [u8] {
self.inner.slice()
}
fn pit(&self) -> Self::PointInTime {
self.inner.pit()
}
fn restore_pit(&mut self, pit: Self::PointInTime) {
self.inner.restore_pit(pit)
}
fn advance(&mut self) -> Option<()> {
None
}
fn recorder(&self) -> Option<&Recorder> {
self.inner.recorder()
}
#[inline]
unsafe fn is_valid_utf8() -> bool {
T::is_valid_utf8()
}
}
#[cfg(test)]
mod tests {
use crate::*;
#[test]
fn test_stop() {
let mut parser = StrParser::new("123456789");
let mut parser = parser.record();
parser.consume_len(5).unwrap();
assert_eq!("12345", parser.to_str());
assert_eq!( "12345", parser.stop().consume_to_str() );
}
}