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
mod stateful;
mod buffer;
mod slice;
pub mod data_source;
use std::io;
use {ParseResult, Input};
pub use self::slice::SliceStream;
pub use self::data_source::DataSource;
pub use self::stateful::Source;
pub use self::buffer::{
Buffer,
FixedSizeBuffer,
GrowingBuffer,
};
#[derive(Debug)]
pub enum ParseError<'a, I, E>
where I: 'a {
ParseError(&'a [I], E),
Incomplete(usize),
IoError(io::Error),
EndOfInput,
Retry,
}
impl<'a, I, E> PartialEq for ParseError<'a, I, E>
where E: PartialEq, I: PartialEq {
#[inline]
fn eq(&self, other: &ParseError<'a, I, E>) -> bool {
match (self, other) {
(&ParseError::ParseError(ref b1, ref e1), &ParseError::ParseError(ref b2, ref e2)) => b1 == b2 && e1 == e2,
(&ParseError::Incomplete(n1), &ParseError::Incomplete(n2)) => n1 == n2,
(&ParseError::EndOfInput, &ParseError::EndOfInput) => true,
(&ParseError::Retry, &ParseError::Retry) => true,
_ => false,
}
}
}
pub trait Stream<'a, 'i> {
type Item: 'i;
#[inline]
fn parse<F, T, E>(&'a mut self, f: F) -> Result<T, ParseError<'i, Self::Item, E>>
where F: FnOnce(Input<'i, Self::Item>) -> ParseResult<'i, Self::Item, T, E>,
T: 'i,
E: 'i;
}
pub trait IntoStream<'a, 'i> {
type Item: 'i;
type Into: Stream<'a, 'i, Item=Self::Item>;
#[inline]
fn into_stream(self) -> Self::Into;
}