Coverage Report

Created: 2025-10-13 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/combine-4.6.7/src/stream/easy.rs
Line
Count
Source
1
//! Stream wrapper which provides an informative and easy to use error type.
2
//!
3
//! Unless you have specific constraints preventing you from using this error type (such as being
4
//! a `no_std` environment) you probably want to use this stream type. It can easily be used
5
//! through the [`EasyParser::easy_parse`] method.
6
//!
7
//! The provided `Errors` type is roughly the same as `ParseError` in combine 1.x and 2.x.
8
//!
9
//! ```
10
//! #[macro_use]
11
//! extern crate combine;
12
//! use combine::{easy, Parser, EasyParser, Stream, many1};
13
//! use combine::parser::char::letter;
14
//! use combine::stream::StreamErrorFor;
15
//! use combine::error::{ParseError, StreamError};
16
//!
17
//! fn main() {
18
//!     parser!{
19
//!        fn parser[Input]()(Input) -> String
20
//!         where [
21
//!             Input: Stream<Token = char, Error = easy::ParseError<Input>>,
22
//!             Input::Range: PartialEq,
23
//!             // If we want to use the error type explicitly we need to help rustc infer
24
//!             // `StreamError` to `easy::Error` (rust-lang/rust#24159)
25
//!             Input::Error: ParseError<
26
//!                 Input::Token,
27
//!                 Input::Range,
28
//!                 Input::Position,
29
//!                 StreamError = easy::Error<Input::Token, Input::Range>
30
//!             >
31
//!         ]
32
//!         {
33
//!             many1(letter()).and_then(|word: String| {
34
//!                 if word == "combine" {
35
//!                     Ok(word)
36
//!                 } else {
37
//!                     Err(easy::Error::Expected(easy::Info::Static("combine")))
38
//!                 }
39
//!             })
40
//!         }
41
//!     }
42
//!
43
//!     parser!{
44
//!        fn parser2[Input]()(Input) -> String
45
//!         where [
46
//!             Input: Stream<Token = char>,
47
//!         ]
48
//!         {
49
//!             many1(letter()).and_then(|word: String| {
50
//!                 if word == "combine" {
51
//!                     Ok(word)
52
//!                 } else {
53
//!                     // Alternatively it is possible to only use the methods provided by the
54
//!                     // `StreamError` trait.
55
//!                     // In that case the extra bound is not necessary (and this method will work
56
//!                     // for other errors than `easy::Errors`)
57
//!                     Err(StreamErrorFor::<Input>::expected_static_message("combine"))
58
//!                 }
59
//!             })
60
//!         }
61
//!     }
62
//!
63
//!     let input = "combin";
64
//!     let expected_error = Err(easy::Errors {
65
//!         errors: vec![
66
//!             easy::Error::Expected("combine".into())
67
//!         ],
68
//!         position: 0,
69
//!     });
70
//!     assert_eq!(
71
//!         parser().easy_parse(input).map_err(|err| err.map_position(|p| p.translate_position(input))),
72
//!         expected_error
73
//!     );
74
//!     assert_eq!(
75
//!         parser2().easy_parse(input).map_err(|err| err.map_position(|p| p.translate_position(input))),
76
//!         expected_error
77
//!     );
78
//! }
79
//!
80
//! ```
81
//!
82
//! [`EasyParser::easy_parse`]: super::super::parser::EasyParser::easy_parse
83
use std::{error::Error as StdError, fmt};
84
85
use crate::error::{Info as PrimitiveInfo, ParseResult, StreamError, Tracked};
86
87
use crate::stream::{
88
    Positioned, RangeStream, RangeStreamOnce, ResetStream, StreamErrorFor, StreamOnce,
89
};
90
91
/// Enum holding error information. Variants are defined for `Stream::Token` and `Stream::Range` as
92
/// well as string variants holding easy descriptions.
93
///
94
/// As there is implementations of `From` for `String` and `&'static str` the
95
/// constructor need not be used directly as calling `msg.into()` should turn a message into the
96
/// correct `Info` variant.
97
#[derive(Clone, Debug)]
98
pub enum Info<T, R> {
99
    Token(T),
100
    Range(R),
101
    Owned(String),
102
    Static(&'static str),
103
}
104
105
impl<T, R, F> From<PrimitiveInfo<T, R, F>> for Info<T, R>
106
where
107
    F: fmt::Display,
108
{
109
0
    fn from(info: PrimitiveInfo<T, R, F>) -> Self {
110
0
        match info {
111
0
            PrimitiveInfo::Token(b) => Info::Token(b),
112
0
            PrimitiveInfo::Range(b) => Info::Range(b),
113
0
            PrimitiveInfo::Static(b) => Info::Static(b),
114
0
            PrimitiveInfo::Format(b) => Info::Owned(b.to_string()),
115
        }
116
0
    }
117
}
118
119
impl<T, R> Info<T, R> {
120
0
    pub fn map_token<F, U>(self, f: F) -> Info<U, R>
121
0
    where
122
0
        F: FnOnce(T) -> U,
123
    {
124
        use self::Info::*;
125
126
0
        match self {
127
0
            Token(t) => Token(f(t)),
128
0
            Range(r) => Range(r),
129
0
            Owned(s) => Owned(s),
130
0
            Static(x) => Static(x),
131
        }
132
0
    }
133
134
4.95k
    pub fn map_range<F, S>(self, f: F) -> Info<T, S>
135
4.95k
    where
136
4.95k
        F: FnOnce(R) -> S,
137
    {
138
        use self::Info::*;
139
140
4.95k
        match self {
141
763
            Token(t) => Token(t),
142
0
            Range(r) => Range(f(r)),
143
3.01k
            Owned(s) => Owned(s),
144
1.17k
            Static(x) => Static(x),
145
        }
146
4.95k
    }
<combine::stream::easy::Info<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&[u8]>::{closure#2}, alloc::string::String>
Line
Count
Source
134
4.95k
    pub fn map_range<F, S>(self, f: F) -> Info<T, S>
135
4.95k
    where
136
4.95k
        F: FnOnce(R) -> S,
137
    {
138
        use self::Info::*;
139
140
4.95k
        match self {
141
763
            Token(t) => Token(t),
142
0
            Range(r) => Range(f(r)),
143
3.01k
            Owned(s) => Owned(s),
144
1.17k
            Static(x) => Static(x),
145
        }
146
4.95k
    }
Unexecuted instantiation: <combine::stream::easy::Info<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&mut std::net::tcp::TcpStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Info<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&mut std::os::unix::net::stream::UnixStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Info<_, _>>::map_range::<_, _>
147
}
148
149
impl<T: PartialEq, R: PartialEq> PartialEq for Info<T, R> {
150
1.65M
    fn eq(&self, other: &Info<T, R>) -> bool {
151
1.65M
        match (self, other) {
152
253
            (&Info::Token(ref l), &Info::Token(ref r)) => l == r,
153
0
            (&Info::Range(ref l), &Info::Range(ref r)) => l == r,
154
1.49M
            (&Info::Owned(ref l), &Info::Owned(ref r)) => l == r,
155
1.03k
            (&Info::Static(l), &Info::Owned(ref r)) => l == r,
156
0
            (&Info::Owned(ref l), &Info::Static(r)) => l == r,
157
157k
            (&Info::Static(l), &Info::Static(r)) => l == r,
158
2.34k
            _ => false,
159
        }
160
1.65M
    }
<combine::stream::easy::Info<u8, &[u8]> as core::cmp::PartialEq>::eq
Line
Count
Source
150
1.65M
    fn eq(&self, other: &Info<T, R>) -> bool {
151
1.65M
        match (self, other) {
152
253
            (&Info::Token(ref l), &Info::Token(ref r)) => l == r,
153
0
            (&Info::Range(ref l), &Info::Range(ref r)) => l == r,
154
1.49M
            (&Info::Owned(ref l), &Info::Owned(ref r)) => l == r,
155
1.03k
            (&Info::Static(l), &Info::Owned(ref r)) => l == r,
156
0
            (&Info::Owned(ref l), &Info::Static(r)) => l == r,
157
157k
            (&Info::Static(l), &Info::Static(r)) => l == r,
158
2.34k
            _ => false,
159
        }
160
1.65M
    }
Unexecuted instantiation: <combine::stream::easy::Info<_, _> as core::cmp::PartialEq>::eq
161
}
162
impl<T: fmt::Display, R: fmt::Display> fmt::Display for Info<T, R> {
163
4.95k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164
4.95k
        match *self {
165
763
            Info::Token(ref c) => write!(f, "`{}`", c),
166
0
            Info::Range(ref c) => write!(f, "`{}`", c),
167
3.01k
            Info::Owned(ref s) => write!(f, "{}", s),
168
1.17k
            Info::Static(s) => write!(f, "{}", s),
169
        }
170
4.95k
    }
<combine::stream::easy::Info<u8, alloc::string::String> as core::fmt::Display>::fmt
Line
Count
Source
163
4.95k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164
4.95k
        match *self {
165
763
            Info::Token(ref c) => write!(f, "`{}`", c),
166
0
            Info::Range(ref c) => write!(f, "`{}`", c),
167
3.01k
            Info::Owned(ref s) => write!(f, "{}", s),
168
1.17k
            Info::Static(s) => write!(f, "{}", s),
169
        }
170
4.95k
    }
Unexecuted instantiation: <combine::stream::easy::Info<_, _> as core::fmt::Display>::fmt
171
}
172
173
impl<R> From<char> for Info<char, R> {
174
0
    fn from(s: char) -> Info<char, R> {
175
0
        Info::Token(s)
176
0
    }
177
}
178
impl<T, R> From<String> for Info<T, R> {
179
0
    fn from(s: String) -> Info<T, R> {
180
0
        Info::Owned(s)
181
0
    }
182
}
183
184
impl<T, R> From<&'static str> for Info<T, R> {
185
161k
    fn from(s: &'static str) -> Info<T, R> {
186
161k
        Info::Static(s)
187
161k
    }
<combine::stream::easy::Info<u8, &[u8]> as core::convert::From<&str>>::from
Line
Count
Source
185
161k
    fn from(s: &'static str) -> Info<T, R> {
186
161k
        Info::Static(s)
187
161k
    }
Unexecuted instantiation: <combine::stream::easy::Info<_, _> as core::convert::From<&str>>::from
188
}
189
190
impl<R> From<u8> for Info<u8, R> {
191
0
    fn from(s: u8) -> Info<u8, R> {
192
0
        Info::Token(s)
193
0
    }
194
}
195
196
/// Enum used to store information about an error that has occurred during parsing.
197
#[derive(Debug)]
198
pub enum Error<T, R> {
199
    /// Error indicating an unexpected token has been encountered in the stream
200
    Unexpected(Info<T, R>),
201
    /// Error indicating that the parser expected something else
202
    Expected(Info<T, R>),
203
    /// Generic message
204
    Message(Info<T, R>),
205
    /// Variant for containing other types of errors
206
    Other(Box<dyn StdError + Send + Sync>),
207
}
208
209
impl<Item, Range> StreamError<Item, Range> for Error<Item, Range>
210
where
211
    Item: PartialEq,
212
    Range: PartialEq,
213
{
214
    #[inline]
215
1.54k
    fn unexpected_token(token: Item) -> Self {
216
1.54k
        Error::Unexpected(Info::Token(token))
217
1.54k
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::unexpected_token
Line
Count
Source
215
1.54k
    fn unexpected_token(token: Item) -> Self {
216
1.54k
        Error::Unexpected(Info::Token(token))
217
1.54k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::unexpected_token
218
    #[inline]
219
0
    fn unexpected_range(token: Range) -> Self {
220
0
        Error::Unexpected(Info::Range(token))
221
0
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::unexpected_range
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::unexpected_range
222
    #[inline]
223
0
    fn unexpected_format<T>(msg: T) -> Self
224
0
    where
225
0
        T: fmt::Display,
226
    {
227
0
        Error::Unexpected(Info::Owned(msg.to_string()))
228
0
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::unexpected_format::<&str>
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::unexpected_format::<_>
229
    #[inline]
230
160k
    fn unexpected_static_message(msg: &'static str) -> Self {
231
160k
        Error::Unexpected(Info::Static(msg))
232
160k
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::unexpected_static_message
Line
Count
Source
230
160k
    fn unexpected_static_message(msg: &'static str) -> Self {
231
160k
        Error::Unexpected(Info::Static(msg))
232
160k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::unexpected_static_message
233
234
    #[inline]
235
0
    fn expected_token(token: Item) -> Self {
236
0
        Error::Expected(Info::Token(token))
237
0
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::expected_token
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::expected_token
238
    #[inline]
239
0
    fn expected_range(token: Range) -> Self {
240
0
        Error::Expected(Info::Range(token))
241
0
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::expected_range
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::expected_range
242
    #[inline]
243
0
    fn expected_format<T>(msg: T) -> Self
244
0
    where
245
0
        T: fmt::Display,
246
    {
247
0
        Error::Expected(Info::Owned(msg.to_string()))
248
0
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::expected_format::<&str>
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::expected_format::<_>
249
    #[inline]
250
461
    fn expected_static_message(msg: &'static str) -> Self {
251
461
        Error::Expected(Info::Static(msg))
252
461
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::expected_static_message
Line
Count
Source
250
461
    fn expected_static_message(msg: &'static str) -> Self {
251
461
        Error::Expected(Info::Static(msg))
252
461
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::expected_static_message
253
254
    #[inline]
255
512k
    fn message_format<T>(msg: T) -> Self
256
512k
    where
257
512k
        T: fmt::Display,
258
    {
259
512k
        Error::Message(Info::Owned(msg.to_string()))
260
512k
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::message_format::<core::fmt::Arguments>
Line
Count
Source
255
512k
    fn message_format<T>(msg: T) -> Self
256
512k
    where
257
512k
        T: fmt::Display,
258
    {
259
512k
        Error::Message(Info::Owned(msg.to_string()))
260
512k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::message_format::<_>
261
    #[inline]
262
875
    fn message_static_message(msg: &'static str) -> Self {
263
875
        Error::Message(Info::Static(msg))
264
875
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::message_static_message
Line
Count
Source
262
875
    fn message_static_message(msg: &'static str) -> Self {
263
875
        Error::Message(Info::Static(msg))
264
875
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::message_static_message
265
    #[inline]
266
0
    fn message_token(token: Item) -> Self {
267
0
        Error::Message(Info::Token(token))
268
0
    }
269
    #[inline]
270
0
    fn message_range(token: Range) -> Self {
271
0
        Error::Message(Info::Range(token))
272
0
    }
273
274
161k
    fn is_unexpected_end_of_input(&self) -> bool {
275
161k
        *self == Self::end_of_input()
276
161k
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::is_unexpected_end_of_input
Line
Count
Source
274
161k
    fn is_unexpected_end_of_input(&self) -> bool {
275
161k
        *self == Self::end_of_input()
276
161k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::is_unexpected_end_of_input
277
278
    #[inline]
279
265
    fn other<E>(err: E) -> Self
280
265
    where
281
265
        E: StdError + Send + Sync + 'static,
282
    {
283
265
        err.into()
284
265
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::other::<alloc::string::FromUtf8Error>
Line
Count
Source
279
16
    fn other<E>(err: E) -> Self
280
16
    where
281
16
        E: StdError + Send + Sync + 'static,
282
    {
283
16
        err.into()
284
16
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::other::<core::num::dec2flt::ParseFloatError>
Line
Count
Source
279
42
    fn other<E>(err: E) -> Self
280
42
    where
281
42
        E: StdError + Send + Sync + 'static,
282
    {
283
42
        err.into()
284
42
    }
<combine::stream::easy::Error<u8, &[u8]> as combine::error::StreamError<u8, &[u8]>>::other::<core::str::error::Utf8Error>
Line
Count
Source
279
207
    fn other<E>(err: E) -> Self
280
207
    where
281
207
        E: StdError + Send + Sync + 'static,
282
    {
283
207
        err.into()
284
207
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as combine::error::StreamError<_, _>>::other::<_>
285
286
    #[inline]
287
0
    fn into_other<T>(self) -> T
288
0
    where
289
0
        T: StreamError<Item, Range>,
290
    {
291
0
        match self {
292
0
            Error::Unexpected(info) => match info {
293
0
                Info::Token(x) => T::unexpected_token(x),
294
0
                Info::Range(x) => T::unexpected_range(x),
295
0
                Info::Static(x) => T::unexpected_static_message(x),
296
0
                Info::Owned(x) => T::unexpected_format(x),
297
            },
298
0
            Error::Expected(info) => match info {
299
0
                Info::Token(x) => T::expected_token(x),
300
0
                Info::Range(x) => T::expected_range(x),
301
0
                Info::Static(x) => T::expected_static_message(x),
302
0
                Info::Owned(x) => T::expected_format(x),
303
            },
304
0
            Error::Message(info) => match info {
305
0
                Info::Token(x) => T::expected_token(x),
306
0
                Info::Range(x) => T::expected_range(x),
307
0
                Info::Static(x) => T::expected_static_message(x),
308
0
                Info::Owned(x) => T::expected_format(x),
309
            },
310
0
            Error::Other(err) => T::message_format(err),
311
        }
312
0
    }
313
}
314
315
impl<Item, Range, Position> crate::error::ParseError<Item, Range, Position> for Error<Item, Range>
316
where
317
    Item: PartialEq,
318
    Range: PartialEq,
319
    Position: Default,
320
{
321
    type StreamError = Self;
322
    #[inline]
323
0
    fn empty(_: Position) -> Self {
324
0
        Self::message_static_message("")
325
0
    }
326
    #[inline]
327
0
    fn from_error(_: Position, err: Self::StreamError) -> Self {
328
0
        err
329
0
    }
330
331
    #[inline]
332
0
    fn position(&self) -> Position {
333
0
        Position::default()
334
0
    }
335
336
    #[inline]
337
0
    fn set_position(&mut self, _position: Position) {}
338
339
    #[inline]
340
0
    fn add(&mut self, err: Self::StreamError) {
341
0
        *self = err;
342
0
    }
343
344
    #[inline]
345
0
    fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
346
0
    where
347
0
        F: FnOnce(&mut Tracked<Self>),
348
    {
349
0
        f(self_);
350
0
        self_.error = info;
351
0
    }
352
353
0
    fn is_unexpected_end_of_input(&self) -> bool {
354
0
        *self == Self::end_of_input()
355
0
    }
356
357
    #[inline]
358
0
    fn into_other<T>(self) -> T
359
0
    where
360
0
        T: crate::error::ParseError<Item, Range, Position>,
361
    {
362
0
        T::from_error(Position::default(), StreamError::into_other(self))
363
0
    }
364
}
365
366
impl<Item, Range, Position> crate::error::ParseErrorInto<Item, Range, Position>
367
    for Errors<Item, Range, Position>
368
{
369
0
    fn into_other_error<T, Item2, Range2, Position2>(self) -> T
370
0
    where
371
0
        T: crate::error::ParseError<Item2, Range2, Position2>,
372
0
        Item2: From<Item>,
373
0
        Range2: From<Range>,
374
0
        Position2: From<Position>,
375
    {
376
0
        let mut error = T::empty(self.position.into());
377
0
        for err in self.errors {
378
0
            error.add(crate::error::StreamErrorInto::<Item, Range>::into_other_error(err));
379
0
        }
380
0
        error
381
0
    }
382
}
383
384
impl<Item, Range> crate::error::StreamErrorInto<Item, Range> for Error<Item, Range> {
385
0
    fn into_other_error<T, Item2, Range2>(self) -> T
386
0
    where
387
0
        T: crate::error::StreamError<Item2, Range2>,
388
0
        Item2: From<Item>,
389
0
        Range2: From<Range>,
390
    {
391
0
        match self {
392
0
            Error::Unexpected(info) => match info {
393
0
                Info::Token(x) => T::unexpected_token(x.into()),
394
0
                Info::Range(x) => T::unexpected_range(x.into()),
395
0
                Info::Static(x) => T::unexpected_static_message(x),
396
0
                Info::Owned(x) => T::unexpected_format(x),
397
            },
398
0
            Error::Expected(info) => match info {
399
0
                Info::Token(x) => T::expected_token(x.into()),
400
0
                Info::Range(x) => T::expected_range(x.into()),
401
0
                Info::Static(x) => T::expected_static_message(x),
402
0
                Info::Owned(x) => T::expected_format(x),
403
            },
404
0
            Error::Message(info) => match info {
405
0
                Info::Token(x) => T::expected_token(x.into()),
406
0
                Info::Range(x) => T::expected_range(x.into()),
407
0
                Info::Static(x) => T::expected_static_message(x),
408
0
                Info::Owned(x) => T::expected_format(x),
409
            },
410
0
            Error::Other(err) => T::message_format(err),
411
        }
412
0
    }
413
}
414
415
impl<Item, Range, Position> crate::error::ParseError<Item, Range, Position>
416
    for Errors<Item, Range, Position>
417
where
418
    Item: PartialEq,
419
    Range: PartialEq,
420
    Position: Ord + Clone,
421
{
422
    type StreamError = Error<Item, Range>;
423
    #[inline]
424
4.22k
    fn empty(pos: Position) -> Self {
425
4.22k
        Errors::empty(pos)
426
4.22k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::empty
Line
Count
Source
424
4.22k
    fn empty(pos: Position) -> Self {
425
4.22k
        Errors::empty(pos)
426
4.22k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::empty
427
    #[inline]
428
145k
    fn from_error(position: Position, err: Self::StreamError) -> Self {
429
145k
        Self::new(position, err)
430
145k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::from_error
Line
Count
Source
428
145k
    fn from_error(position: Position, err: Self::StreamError) -> Self {
429
145k
        Self::new(position, err)
430
145k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::from_error
431
432
    #[inline]
433
0
    fn position(&self) -> Position {
434
0
        self.position.clone()
435
0
    }
436
437
    #[inline]
438
0
    fn set_position(&mut self, position: Position) {
439
0
        self.position = position;
440
0
    }
441
442
    #[inline]
443
1.96k
    fn merge(self, other: Self) -> Self {
444
1.96k
        Errors::merge(self, other)
445
1.96k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::merge
Line
Count
Source
443
1.96k
    fn merge(self, other: Self) -> Self {
444
1.96k
        Errors::merge(self, other)
445
1.96k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::merge
446
447
    #[inline]
448
522k
    fn add(&mut self, err: Self::StreamError) {
449
522k
        self.add_error(err);
450
522k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::add
Line
Count
Source
448
522k
    fn add(&mut self, err: Self::StreamError) {
449
522k
        self.add_error(err);
450
522k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::add
451
452
    #[inline]
453
461
    fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
454
461
    where
455
461
        F: FnOnce(&mut Tracked<Self>),
456
    {
457
461
        let start = self_.error.errors.len();
458
461
        f(self_);
459
        // Replace all expected errors that were added from the previous add_error
460
        // with this expected error
461
461
        let mut i = 0;
462
461
        self_.error.errors.retain(|e| {
463
461
            if i < start {
464
461
                i += 1;
465
461
                true
466
            } else {
467
0
                match *e {
468
0
                    Error::Expected(_) => false,
469
0
                    _ => true,
470
                }
471
            }
472
461
        });
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::set_expected::<<combine::parser::error::Expected<combine::parser::combinator::NoPartial<combine::parser::sequence::With<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::crlf<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, combine::parser::error::Expected<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::newline<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, &str>>>, &str> as combine::parser::Parser<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>>::add_error::{closure#0}>::{closure#0}
Line
Count
Source
462
383
        self_.error.errors.retain(|e| {
463
383
            if i < start {
464
383
                i += 1;
465
383
                true
466
            } else {
467
0
                match *e {
468
0
                    Error::Expected(_) => false,
469
0
                    _ => true,
470
                }
471
            }
472
383
        });
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::set_expected::<<combine::parser::error::Expected<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::newline<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, &str> as combine::parser::Parser<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>>::add_error::{closure#0}>::{closure#0}
Line
Count
Source
462
78
        self_.error.errors.retain(|e| {
463
78
            if i < start {
464
78
                i += 1;
465
78
                true
466
            } else {
467
0
                match *e {
468
0
                    Error::Expected(_) => false,
469
0
                    _ => true,
470
                }
471
            }
472
78
        });
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::set_expected::<_>::{closure#0}
473
461
        self_.error.add(info);
474
461
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::set_expected::<<combine::parser::error::Expected<combine::parser::combinator::NoPartial<combine::parser::sequence::With<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::crlf<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, combine::parser::error::Expected<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::newline<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, &str>>>, &str> as combine::parser::Parser<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>>::add_error::{closure#0}>
Line
Count
Source
453
383
    fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
454
383
    where
455
383
        F: FnOnce(&mut Tracked<Self>),
456
    {
457
383
        let start = self_.error.errors.len();
458
383
        f(self_);
459
        // Replace all expected errors that were added from the previous add_error
460
        // with this expected error
461
383
        let mut i = 0;
462
383
        self_.error.errors.retain(|e| {
463
            if i < start {
464
                i += 1;
465
                true
466
            } else {
467
                match *e {
468
                    Error::Expected(_) => false,
469
                    _ => true,
470
                }
471
            }
472
        });
473
383
        self_.error.add(info);
474
383
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::set_expected::<<combine::parser::error::Expected<combine::parser::token::Satisfy<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>, combine::parser::byte::newline<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>::{closure#0}>, &str> as combine::parser::Parser<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>>>>::add_error::{closure#0}>
Line
Count
Source
453
78
    fn set_expected<F>(self_: &mut Tracked<Self>, info: Self::StreamError, f: F)
454
78
    where
455
78
        F: FnOnce(&mut Tracked<Self>),
456
    {
457
78
        let start = self_.error.errors.len();
458
78
        f(self_);
459
        // Replace all expected errors that were added from the previous add_error
460
        // with this expected error
461
78
        let mut i = 0;
462
78
        self_.error.errors.retain(|e| {
463
            if i < start {
464
                i += 1;
465
                true
466
            } else {
467
                match *e {
468
                    Error::Expected(_) => false,
469
                    _ => true,
470
                }
471
            }
472
        });
473
78
        self_.error.add(info);
474
78
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::set_expected::<_>
475
476
0
    fn clear_expected(&mut self) {
477
0
        self.errors.retain(|e| match *e {
478
0
            Error::Expected(_) => false,
479
0
            _ => true,
480
0
        })
481
0
    }
482
483
153k
    fn is_unexpected_end_of_input(&self) -> bool {
484
153k
        self.errors
485
153k
            .iter()
486
153k
            .any(StreamError::is_unexpected_end_of_input)
487
153k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>> as combine::error::ParseError<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::is_unexpected_end_of_input
Line
Count
Source
483
153k
    fn is_unexpected_end_of_input(&self) -> bool {
484
153k
        self.errors
485
153k
            .iter()
486
153k
            .any(StreamError::is_unexpected_end_of_input)
487
153k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as combine::error::ParseError<_, _, _>>::is_unexpected_end_of_input
488
489
    #[inline]
490
0
    fn into_other<T>(mut self) -> T
491
0
    where
492
0
        T: crate::error::ParseError<Item, Range, Position>,
493
    {
494
0
        match self.errors.pop() {
495
0
            Some(err) => T::from_error(self.position, StreamError::into_other(err)),
496
0
            None => T::empty(self.position),
497
        }
498
0
    }
499
}
500
501
impl<T, R> Error<T, R> {
502
0
    pub fn map_token<F, U>(self, f: F) -> Error<U, R>
503
0
    where
504
0
        F: FnOnce(T) -> U,
505
    {
506
        use self::Error::*;
507
508
0
        match self {
509
0
            Unexpected(x) => Unexpected(x.map_token(f)),
510
0
            Expected(x) => Expected(x.map_token(f)),
511
0
            Message(x) => Message(x.map_token(f)),
512
0
            Other(x) => Other(x),
513
        }
514
0
    }
515
516
5.21k
    pub fn map_range<F, S>(self, f: F) -> Error<T, S>
517
5.21k
    where
518
5.21k
        F: FnOnce(R) -> S,
519
    {
520
        use self::Error::*;
521
522
5.21k
        match self {
523
832
            Unexpected(x) => Unexpected(x.map_range(f)),
524
227
            Expected(x) => Expected(x.map_range(f)),
525
3.89k
            Message(x) => Message(x.map_range(f)),
526
265
            Other(x) => Other(x),
527
        }
528
5.21k
    }
<combine::stream::easy::Error<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&[u8]>::{closure#2}, alloc::string::String>
Line
Count
Source
516
5.21k
    pub fn map_range<F, S>(self, f: F) -> Error<T, S>
517
5.21k
    where
518
5.21k
        F: FnOnce(R) -> S,
519
    {
520
        use self::Error::*;
521
522
5.21k
        match self {
523
832
            Unexpected(x) => Unexpected(x.map_range(f)),
524
227
            Expected(x) => Expected(x.map_range(f)),
525
3.89k
            Message(x) => Message(x.map_range(f)),
526
265
            Other(x) => Other(x),
527
        }
528
5.21k
    }
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&mut std::net::tcp::TcpStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Error<u8, &[u8]>>::map_range::<&mut <redis::parser::Parser>::parse_value<&mut std::os::unix::net::stream::UnixStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::map_range::<_, _>
529
}
530
531
impl<T: PartialEq, R: PartialEq> PartialEq for Error<T, R> {
532
2.20M
    fn eq(&self, other: &Error<T, R>) -> bool {
533
2.20M
        match (self, other) {
534
160k
            (&Error::Unexpected(ref l), &Error::Unexpected(ref r))
535
0
            | (&Error::Expected(ref l), &Error::Expected(ref r))
536
1.65M
            | (&Error::Message(ref l), &Error::Message(ref r)) => l == r,
537
543k
            _ => false,
538
        }
539
2.20M
    }
<combine::stream::easy::Error<u8, &[u8]> as core::cmp::PartialEq>::eq
Line
Count
Source
532
2.20M
    fn eq(&self, other: &Error<T, R>) -> bool {
533
2.20M
        match (self, other) {
534
160k
            (&Error::Unexpected(ref l), &Error::Unexpected(ref r))
535
0
            | (&Error::Expected(ref l), &Error::Expected(ref r))
536
1.65M
            | (&Error::Message(ref l), &Error::Message(ref r)) => l == r,
537
543k
            _ => false,
538
        }
539
2.20M
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as core::cmp::PartialEq>::eq
540
}
541
542
impl<T, R, E> From<E> for Error<T, R>
543
where
544
    E: StdError + 'static + Send + Sync,
545
{
546
265
    fn from(e: E) -> Error<T, R> {
547
265
        Error::Other(Box::new(e))
548
265
    }
<combine::stream::easy::Error<u8, &[u8]> as core::convert::From<alloc::string::FromUtf8Error>>::from
Line
Count
Source
546
16
    fn from(e: E) -> Error<T, R> {
547
16
        Error::Other(Box::new(e))
548
16
    }
<combine::stream::easy::Error<u8, &[u8]> as core::convert::From<core::num::dec2flt::ParseFloatError>>::from
Line
Count
Source
546
42
    fn from(e: E) -> Error<T, R> {
547
42
        Error::Other(Box::new(e))
548
42
    }
<combine::stream::easy::Error<u8, &[u8]> as core::convert::From<core::str::error::Utf8Error>>::from
Line
Count
Source
546
207
    fn from(e: E) -> Error<T, R> {
547
207
        Error::Other(Box::new(e))
548
207
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as core::convert::From<_>>::from
549
}
550
551
impl<T, R> Error<T, R> {
552
    /// Returns the `end_of_input` error.
553
161k
    pub fn end_of_input() -> Error<T, R> {
554
161k
        Error::Unexpected("end of input".into())
555
161k
    }
<combine::stream::easy::Error<u8, &[u8]>>::end_of_input
Line
Count
Source
553
161k
    pub fn end_of_input() -> Error<T, R> {
554
161k
        Error::Unexpected("end of input".into())
555
161k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::end_of_input
556
557
    /// Formats a slice of errors in a human readable way.
558
    ///
559
    /// ```rust
560
    /// # extern crate combine;
561
    /// # use combine::*;
562
    /// # use combine::parser::char::*;
563
    /// # use combine::stream::position::{self, SourcePosition};
564
    ///
565
    /// # fn main() {
566
    /// let input = r"
567
    ///   ,123
568
    /// ";
569
    /// let result = spaces().silent().with(char('.').or(char('a')).or(digit()))
570
    ///     .easy_parse(position::Stream::new(input));
571
    /// let m = format!("{}", result.unwrap_err());
572
    /// let expected = r"Parse error at line: 2, column: 3
573
    /// Unexpected `,`
574
    /// Expected `.`, `a` or digit
575
    /// ";
576
    /// assert_eq!(m, expected);
577
    /// # }
578
    /// ```
579
1.68k
    pub fn fmt_errors(errors: &[Error<T, R>], f: &mut fmt::Formatter<'_>) -> fmt::Result
580
1.68k
    where
581
1.68k
        T: fmt::Display,
582
1.68k
        R: fmt::Display,
583
    {
584
        // First print the token that we did not expect
585
        // There should really just be one unexpected message at this point though we print them
586
        // all to be safe
587
5.21k
        let unexpected = errors.iter().filter(|e| match **e {
588
832
            Error::Unexpected(_) => true,
589
4.38k
            _ => false,
590
5.21k
        });
<combine::stream::easy::Error<u8, alloc::string::String>>::fmt_errors::{closure#0}
Line
Count
Source
587
5.21k
        let unexpected = errors.iter().filter(|e| match **e {
588
832
            Error::Unexpected(_) => true,
589
4.38k
            _ => false,
590
5.21k
        });
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::fmt_errors::{closure#0}
591
2.52k
        for error in unexpected {
592
832
            writeln!(f, "{}", error)?;
593
        }
594
595
        // Then we print out all the things that were expected in a comma separated list
596
        // 'Expected 'a', 'expression' or 'let'
597
3.37k
        let iter = || {
598
10.4k
            errors.iter().filter_map(|e| match *e {
599
454
                Error::Expected(ref err) => Some(err),
600
9.98k
                _ => None,
601
10.4k
            })
<combine::stream::easy::Error<u8, alloc::string::String>>::fmt_errors::{closure#1}::{closure#0}
Line
Count
Source
598
10.4k
            errors.iter().filter_map(|e| match *e {
599
454
                Error::Expected(ref err) => Some(err),
600
9.98k
                _ => None,
601
10.4k
            })
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::fmt_errors::{closure#1}::{closure#0}
602
3.37k
        };
<combine::stream::easy::Error<u8, alloc::string::String>>::fmt_errors::{closure#1}
Line
Count
Source
597
3.37k
        let iter = || {
598
3.37k
            errors.iter().filter_map(|e| match *e {
599
                Error::Expected(ref err) => Some(err),
600
                _ => None,
601
            })
602
3.37k
        };
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::fmt_errors::{closure#1}
603
1.68k
        let expected_count = iter().count();
604
1.68k
        for (i, message) in iter().enumerate() {
605
227
            let s = match i {
606
227
                0 => "Expected",
607
0
                _ if i < expected_count - 1 => ",",
608
                // Last expected message to be written
609
0
                _ => " or",
610
            };
611
227
            write!(f, "{} {}", s, message)?;
612
        }
613
1.68k
        if expected_count != 0 {
614
227
            writeln!(f)?;
615
1.46k
        }
616
        // If there are any generic messages we print them out last
617
5.21k
        let messages = errors.iter().filter(|e| match **e {
618
4.15k
            Error::Message(_) | Error::Other(_) => true,
619
1.05k
            _ => false,
620
5.21k
        });
<combine::stream::easy::Error<u8, alloc::string::String>>::fmt_errors::{closure#2}
Line
Count
Source
617
5.21k
        let messages = errors.iter().filter(|e| match **e {
618
4.15k
            Error::Message(_) | Error::Other(_) => true,
619
1.05k
            _ => false,
620
5.21k
        });
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::fmt_errors::{closure#2}
621
5.84k
        for error in messages {
622
4.15k
            writeln!(f, "{}", error)?;
623
        }
624
1.68k
        Ok(())
625
1.68k
    }
<combine::stream::easy::Error<u8, alloc::string::String>>::fmt_errors
Line
Count
Source
579
1.68k
    pub fn fmt_errors(errors: &[Error<T, R>], f: &mut fmt::Formatter<'_>) -> fmt::Result
580
1.68k
    where
581
1.68k
        T: fmt::Display,
582
1.68k
        R: fmt::Display,
583
    {
584
        // First print the token that we did not expect
585
        // There should really just be one unexpected message at this point though we print them
586
        // all to be safe
587
1.68k
        let unexpected = errors.iter().filter(|e| match **e {
588
            Error::Unexpected(_) => true,
589
            _ => false,
590
        });
591
2.52k
        for error in unexpected {
592
832
            writeln!(f, "{}", error)?;
593
        }
594
595
        // Then we print out all the things that were expected in a comma separated list
596
        // 'Expected 'a', 'expression' or 'let'
597
1.68k
        let iter = || {
598
            errors.iter().filter_map(|e| match *e {
599
                Error::Expected(ref err) => Some(err),
600
                _ => None,
601
            })
602
        };
603
1.68k
        let expected_count = iter().count();
604
1.68k
        for (i, message) in iter().enumerate() {
605
227
            let s = match i {
606
227
                0 => "Expected",
607
0
                _ if i < expected_count - 1 => ",",
608
                // Last expected message to be written
609
0
                _ => " or",
610
            };
611
227
            write!(f, "{} {}", s, message)?;
612
        }
613
1.68k
        if expected_count != 0 {
614
227
            writeln!(f)?;
615
1.46k
        }
616
        // If there are any generic messages we print them out last
617
1.68k
        let messages = errors.iter().filter(|e| match **e {
618
            Error::Message(_) | Error::Other(_) => true,
619
            _ => false,
620
        });
621
5.84k
        for error in messages {
622
4.15k
            writeln!(f, "{}", error)?;
623
        }
624
1.68k
        Ok(())
625
1.68k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _>>::fmt_errors
626
}
627
628
/// Convenience alias over `Errors` for `StreamOnce` types which makes it possible to specify the
629
/// `Errors` type from a `StreamOnce` by writing `ParseError<Input>` instead of `Errors<Input::Token,
630
/// Input::Range, Input::Position>`
631
pub type ParseError<S> =
632
    Errors<<S as StreamOnce>::Token, <S as StreamOnce>::Range, <S as StreamOnce>::Position>;
633
634
/// Struct which hold information about an error that occurred at a specific position.
635
/// Can hold multiple instances of `Error` if more that one error occurred in the same position.
636
#[derive(Debug, PartialEq)]
637
pub struct Errors<T, R, P> {
638
    /// The position where the error occurred
639
    pub position: P,
640
    /// A vector containing specific information on what errors occurred at `position`. Usually
641
    /// a fully formed message contains one `Unexpected` error and one or more `Expected` errors.
642
    /// `Message` and `Other` may also appear (`combine` never generates these errors on its own)
643
    /// and may warrant custom handling.
644
    pub errors: Vec<Error<T, R>>,
645
}
646
647
impl<T, R, P> Errors<T, R, P> {
648
    /// Constructs a new `ParseError` which occurred at `position`.
649
    #[inline]
650
145k
    pub fn new(position: P, error: Error<T, R>) -> Errors<T, R, P> {
651
145k
        Self::from_errors(position, vec![error])
652
145k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::new
Line
Count
Source
650
145k
    pub fn new(position: P, error: Error<T, R>) -> Errors<T, R, P> {
651
145k
        Self::from_errors(position, vec![error])
652
145k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::new
653
654
    /// Constructs an error with no other information than the position it occurred at.
655
    #[inline]
656
4.22k
    pub fn empty(position: P) -> Errors<T, R, P> {
657
4.22k
        Self::from_errors(position, vec![])
658
4.22k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::empty
Line
Count
Source
656
4.22k
    pub fn empty(position: P) -> Errors<T, R, P> {
657
4.22k
        Self::from_errors(position, vec![])
658
4.22k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::empty
659
660
    /// Constructs a `ParseError` with multiple causes.
661
    #[inline]
662
153k
    pub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P> {
663
153k
        Errors { position, errors }
664
153k
    }
<combine::stream::easy::Errors<u8, alloc::string::String, combine::stream::PointerOffset<[u8]>>>::from_errors
Line
Count
Source
662
1.68k
    pub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P> {
663
1.68k
        Errors { position, errors }
664
1.68k
    }
<combine::stream::easy::Errors<u8, alloc::string::String, usize>>::from_errors
Line
Count
Source
662
1.68k
    pub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P> {
663
1.68k
        Errors { position, errors }
664
1.68k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::from_errors
Line
Count
Source
662
149k
    pub fn from_errors(position: P, errors: Vec<Error<T, R>>) -> Errors<T, R, P> {
663
149k
        Errors { position, errors }
664
149k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::from_errors
665
666
    /// Constructs an end of input error. Should be returned by parsers which encounter end of
667
    /// input unexpectedly.
668
    #[inline]
669
0
    pub fn end_of_input(position: P) -> Errors<T, R, P> {
670
0
        Self::new(position, Error::end_of_input())
671
0
    }
672
673
    /// Adds an error if `error` does not exist in this `ParseError` already (as determined byte
674
    /// `PartialEq`).
675
524k
    pub fn add_error(&mut self, error: Error<T, R>)
676
524k
    where
677
524k
        T: PartialEq,
678
524k
        R: PartialEq,
679
    {
680
        // Don't add duplicate errors
681
2.03M
        if self.errors.iter().all(|err| *err != error) {
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::add_error::{closure#0}
Line
Count
Source
681
2.03M
        if self.errors.iter().all(|err| *err != error) {
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::add_error::{closure#0}
682
333k
            self.errors.push(error);
683
333k
        }
684
524k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::add_error
Line
Count
Source
675
524k
    pub fn add_error(&mut self, error: Error<T, R>)
676
524k
    where
677
524k
        T: PartialEq,
678
524k
        R: PartialEq,
679
    {
680
        // Don't add duplicate errors
681
524k
        if self.errors.iter().all(|err| *err != error) {
682
333k
            self.errors.push(error);
683
333k
        }
684
524k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::add_error
685
686
    /// Removes all `Expected` errors in `self` and adds `info` instead.
687
0
    pub fn set_expected(&mut self, info: Info<T, R>) {
688
        // Remove all other expected messages
689
0
        self.errors.retain(|e| match *e {
690
0
            Error::Expected(_) => false,
691
0
            _ => true,
692
0
        });
693
0
        self.errors.push(Error::Expected(info));
694
0
    }
695
696
    /// Merges two `ParseError`s. If they exist at the same position the errors of `other` are
697
    /// added to `self` (using `add_error` to skip duplicates). If they are not at the same
698
    /// position the error furthest ahead are returned, ignoring the other `ParseError`.
699
1.96k
    pub fn merge(mut self, mut other: Errors<T, R, P>) -> Errors<T, R, P>
700
1.96k
    where
701
1.96k
        P: Ord,
702
1.96k
        T: PartialEq,
703
1.96k
        R: PartialEq,
704
    {
705
        use std::cmp::Ordering;
706
707
        // Only keep the errors which occurred after consuming the most amount of data
708
1.96k
        match self.position.cmp(&other.position) {
709
0
            Ordering::Less => other,
710
0
            Ordering::Greater => self,
711
            Ordering::Equal => {
712
1.96k
                for message in other.errors.drain(..) {
713
1.96k
                    self.add_error(message);
714
1.96k
                }
715
1.96k
                self
716
            }
717
        }
718
1.96k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::merge
Line
Count
Source
699
1.96k
    pub fn merge(mut self, mut other: Errors<T, R, P>) -> Errors<T, R, P>
700
1.96k
    where
701
1.96k
        P: Ord,
702
1.96k
        T: PartialEq,
703
1.96k
        R: PartialEq,
704
    {
705
        use std::cmp::Ordering;
706
707
        // Only keep the errors which occurred after consuming the most amount of data
708
1.96k
        match self.position.cmp(&other.position) {
709
0
            Ordering::Less => other,
710
0
            Ordering::Greater => self,
711
            Ordering::Equal => {
712
1.96k
                for message in other.errors.drain(..) {
713
1.96k
                    self.add_error(message);
714
1.96k
                }
715
1.96k
                self
716
            }
717
        }
718
1.96k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::merge
719
720
    /// Maps the position to a new value
721
1.68k
    pub fn map_position<F, Q>(self, f: F) -> Errors<T, R, Q>
722
1.68k
    where
723
1.68k
        F: FnOnce(P) -> Q,
724
    {
725
1.68k
        Errors::from_errors(f(self.position), self.errors)
726
1.68k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<u8, alloc::string::String, combine::stream::PointerOffset<[u8]>>>::map_position::<<redis::parser::Parser>::parse_value<&mut std::net::tcp::TcpStream>::{closure#3}, usize>
Unexecuted instantiation: <combine::stream::easy::Errors<u8, alloc::string::String, combine::stream::PointerOffset<[u8]>>>::map_position::<<redis::parser::Parser>::parse_value<&mut std::os::unix::net::stream::UnixStream>::{closure#3}, usize>
<combine::stream::easy::Errors<u8, alloc::string::String, combine::stream::PointerOffset<[u8]>>>::map_position::<<redis::parser::Parser>::parse_value<&[u8]>::{closure#3}, usize>
Line
Count
Source
721
1.68k
    pub fn map_position<F, Q>(self, f: F) -> Errors<T, R, Q>
722
1.68k
    where
723
1.68k
        F: FnOnce(P) -> Q,
724
    {
725
1.68k
        Errors::from_errors(f(self.position), self.errors)
726
1.68k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::map_position::<_, _>
727
728
    /// Maps all token variants to a new value
729
0
    pub fn map_token<F, U>(self, mut f: F) -> Errors<U, R, P>
730
0
    where
731
0
        F: FnMut(T) -> U,
732
    {
733
0
        Errors::from_errors(
734
0
            self.position,
735
0
            self.errors
736
0
                .into_iter()
737
0
                .map(|error| error.map_token(&mut f))
738
0
                .collect(),
739
        )
740
0
    }
741
742
    /// Maps all range variants to a new value.
743
    ///
744
    /// ```
745
    /// use combine::*;
746
    /// use combine::parser::range::range;
747
    /// println!(
748
    ///     "{}",
749
    ///     range(&"HTTP"[..])
750
    ///         .easy_parse("HTT")
751
    ///         .unwrap_err()
752
    ///         .map_range(|bytes| format!("{:?}", bytes))
753
    /// );
754
    /// ```
755
1.68k
    pub fn map_range<F, S>(self, mut f: F) -> Errors<T, S, P>
756
1.68k
    where
757
1.68k
        F: FnMut(R) -> S,
758
    {
759
1.68k
        Errors::from_errors(
760
1.68k
            self.position,
761
1.68k
            self.errors
762
1.68k
                .into_iter()
763
5.21k
                .map(|error| error.map_range(&mut f))
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&[u8]>::{closure#2}, alloc::string::String>::{closure#0}
Line
Count
Source
763
5.21k
                .map(|error| error.map_range(&mut f))
Unexecuted instantiation: <combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&mut std::net::tcp::TcpStream>::{closure#2}, alloc::string::String>::{closure#0}
Unexecuted instantiation: <combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&mut std::os::unix::net::stream::UnixStream>::{closure#2}, alloc::string::String>::{closure#0}
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::map_range::<_, _>::{closure#0}
764
1.68k
                .collect(),
765
        )
766
1.68k
    }
<combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&[u8]>::{closure#2}, alloc::string::String>
Line
Count
Source
755
1.68k
    pub fn map_range<F, S>(self, mut f: F) -> Errors<T, S, P>
756
1.68k
    where
757
1.68k
        F: FnMut(R) -> S,
758
    {
759
1.68k
        Errors::from_errors(
760
1.68k
            self.position,
761
1.68k
            self.errors
762
1.68k
                .into_iter()
763
1.68k
                .map(|error| error.map_range(&mut f))
764
1.68k
                .collect(),
765
        )
766
1.68k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&mut std::net::tcp::TcpStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Errors<u8, &[u8], combine::stream::PointerOffset<[u8]>>>::map_range::<<redis::parser::Parser>::parse_value<&mut std::os::unix::net::stream::UnixStream>::{closure#2}, alloc::string::String>
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _>>::map_range::<_, _>
767
}
768
769
impl<T, R, P> StdError for Errors<T, R, P>
770
where
771
    P: fmt::Display + fmt::Debug,
772
    T: fmt::Display + fmt::Debug,
773
    R: fmt::Display + fmt::Debug,
774
{
775
0
    fn description(&self) -> &str {
776
0
        "parse error"
777
0
    }
778
}
779
780
impl<T, R, P> fmt::Display for Errors<T, R, P>
781
where
782
    P: fmt::Display,
783
    T: fmt::Display,
784
    R: fmt::Display,
785
{
786
1.68k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
787
1.68k
        writeln!(f, "Parse error at {}", self.position)?;
788
1.68k
        Error::fmt_errors(&self.errors, f)
789
1.68k
    }
<combine::stream::easy::Errors<u8, alloc::string::String, usize> as core::fmt::Display>::fmt
Line
Count
Source
786
1.68k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
787
1.68k
        writeln!(f, "Parse error at {}", self.position)?;
788
1.68k
        Error::fmt_errors(&self.errors, f)
789
1.68k
    }
Unexecuted instantiation: <combine::stream::easy::Errors<_, _, _> as core::fmt::Display>::fmt
790
}
791
792
impl<T: fmt::Display, R: fmt::Display> fmt::Display for Error<T, R> {
793
4.99k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
794
4.99k
        match *self {
795
832
            Error::Unexpected(ref c) => write!(f, "Unexpected {}", c),
796
0
            Error::Expected(ref s) => write!(f, "Expected {}", s),
797
3.89k
            Error::Message(ref msg) => msg.fmt(f),
798
265
            Error::Other(ref err) => err.fmt(f),
799
        }
800
4.99k
    }
<combine::stream::easy::Error<u8, alloc::string::String> as core::fmt::Display>::fmt
Line
Count
Source
793
4.99k
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
794
4.99k
        match *self {
795
832
            Error::Unexpected(ref c) => write!(f, "Unexpected {}", c),
796
0
            Error::Expected(ref s) => write!(f, "Expected {}", s),
797
3.89k
            Error::Message(ref msg) => msg.fmt(f),
798
265
            Error::Other(ref err) => err.fmt(f),
799
        }
800
4.99k
    }
Unexecuted instantiation: <combine::stream::easy::Error<_, _> as core::fmt::Display>::fmt
801
}
802
803
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
804
pub struct Stream<S>(pub S);
805
806
impl<S> From<S> for Stream<S> {
807
149k
    fn from(stream: S) -> Self {
808
149k
        Stream(stream)
809
149k
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as core::convert::From<combine::stream::MaybePartialStream<&[u8]>>>::from
Line
Count
Source
807
149k
    fn from(stream: S) -> Self {
808
149k
        Stream(stream)
809
149k
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as core::convert::From<_>>::from
810
}
811
812
impl<S> ResetStream for Stream<S>
813
where
814
    S: ResetStream + Positioned,
815
    S::Token: PartialEq,
816
    S::Range: PartialEq,
817
{
818
    type Checkpoint = S::Checkpoint;
819
820
40.3M
    fn checkpoint(&self) -> Self::Checkpoint {
821
40.3M
        self.0.checkpoint()
822
40.3M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::ResetStream>::checkpoint
Line
Count
Source
820
40.3M
    fn checkpoint(&self) -> Self::Checkpoint {
821
40.3M
        self.0.checkpoint()
822
40.3M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::ResetStream>::checkpoint
823
10.8M
    fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error> {
824
10.8M
        self.0
825
10.8M
            .reset(checkpoint)
826
10.8M
            .map_err(crate::error::ParseError::into_other)
827
10.8M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::ResetStream>::reset
Line
Count
Source
823
10.8M
    fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error> {
824
10.8M
        self.0
825
10.8M
            .reset(checkpoint)
826
10.8M
            .map_err(crate::error::ParseError::into_other)
827
10.8M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::ResetStream>::reset
828
}
829
830
impl<S> StreamOnce for Stream<S>
831
where
832
    S: StreamOnce + Positioned,
833
    S::Token: PartialEq,
834
    S::Range: PartialEq,
835
{
836
    type Token = S::Token;
837
    type Range = S::Range;
838
    type Position = S::Position;
839
    type Error = ParseError<S>;
840
841
    #[inline]
842
5.54M
    fn uncons(&mut self) -> Result<Self::Token, StreamErrorFor<Self>> {
843
5.54M
        self.0.uncons().map_err(StreamError::into_other)
844
5.54M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::StreamOnce>::uncons
Line
Count
Source
842
5.54M
    fn uncons(&mut self) -> Result<Self::Token, StreamErrorFor<Self>> {
843
5.54M
        self.0.uncons().map_err(StreamError::into_other)
844
5.54M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::StreamOnce>::uncons
845
846
373k
    fn is_partial(&self) -> bool {
847
373k
        self.0.is_partial()
848
373k
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::StreamOnce>::is_partial
Line
Count
Source
846
373k
    fn is_partial(&self) -> bool {
847
373k
        self.0.is_partial()
848
373k
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::StreamOnce>::is_partial
849
}
850
851
impl<S> RangeStreamOnce for Stream<S>
852
where
853
    S: RangeStream,
854
    S::Token: PartialEq,
855
    S::Range: PartialEq,
856
{
857
    #[inline]
858
16.3M
    fn uncons_range(&mut self, size: usize) -> Result<Self::Range, StreamErrorFor<Self>> {
859
16.3M
        self.0.uncons_range(size).map_err(StreamError::into_other)
860
16.3M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::RangeStreamOnce>::uncons_range
Line
Count
Source
858
16.3M
    fn uncons_range(&mut self, size: usize) -> Result<Self::Range, StreamErrorFor<Self>> {
859
16.3M
        self.0.uncons_range(size).map_err(StreamError::into_other)
860
16.3M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::RangeStreamOnce>::uncons_range
861
862
    #[inline]
863
0
    fn uncons_while<F>(&mut self, f: F) -> Result<Self::Range, StreamErrorFor<Self>>
864
0
    where
865
0
        F: FnMut(Self::Token) -> bool,
866
    {
867
0
        self.0.uncons_while(f).map_err(StreamError::into_other)
868
0
    }
869
870
    #[inline]
871
0
    fn uncons_while1<F>(&mut self, f: F) -> ParseResult<Self::Range, StreamErrorFor<Self>>
872
0
    where
873
0
        F: FnMut(Self::Token) -> bool,
874
    {
875
0
        self.0.uncons_while1(f).map_err(StreamError::into_other)
876
0
    }
877
878
    #[inline]
879
5.56M
    fn distance(&self, end: &Self::Checkpoint) -> usize {
880
5.56M
        self.0.distance(end)
881
5.56M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::RangeStreamOnce>::distance
Line
Count
Source
879
5.56M
    fn distance(&self, end: &Self::Checkpoint) -> usize {
880
5.56M
        self.0.distance(end)
881
5.56M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::RangeStreamOnce>::distance
882
883
5.50M
    fn range(&self) -> Self::Range {
884
5.50M
        self.0.range()
885
5.50M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::RangeStreamOnce>::range
Line
Count
Source
883
5.50M
    fn range(&self) -> Self::Range {
884
5.50M
        self.0.range()
885
5.50M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::RangeStreamOnce>::range
886
}
887
888
impl<S> Positioned for Stream<S>
889
where
890
    S: StreamOnce + Positioned,
891
    S::Token: PartialEq,
892
    S::Range: PartialEq,
893
{
894
6.33M
    fn position(&self) -> S::Position {
895
6.33M
        self.0.position()
896
6.33M
    }
<combine::stream::easy::Stream<combine::stream::MaybePartialStream<&[u8]>> as combine::stream::Positioned>::position
Line
Count
Source
894
6.33M
    fn position(&self) -> S::Position {
895
6.33M
        self.0.position()
896
6.33M
    }
Unexecuted instantiation: <combine::stream::easy::Stream<_> as combine::stream::Positioned>::position
897
}