/rust/registry/src/index.crates.io-1949cf8c6b5b557f/combine-4.6.7/src/stream/state.rs
Line | Count | Source |
1 | | use crate::{ |
2 | | error::ParseResult, |
3 | | stream::{Positioned, RangeStreamOnce, ResetStream, StreamErrorFor, StreamOnce}, |
4 | | }; |
5 | | |
6 | | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] |
7 | | pub struct Stream<S, U> { |
8 | | pub stream: S, |
9 | | pub state: U, |
10 | | } |
11 | | |
12 | | impl<S, U> Positioned for Stream<S, U> |
13 | | where |
14 | | S: Positioned, |
15 | | { |
16 | | #[inline] |
17 | 0 | fn position(&self) -> Self::Position { |
18 | 0 | self.stream.position() |
19 | 0 | } |
20 | | } |
21 | | |
22 | | impl<S, U> ResetStream for Stream<S, U> |
23 | | where |
24 | | S: ResetStream, |
25 | | { |
26 | | type Checkpoint = S::Checkpoint; |
27 | | |
28 | | #[inline] |
29 | 0 | fn checkpoint(&self) -> Self::Checkpoint { |
30 | 0 | self.stream.checkpoint() |
31 | 0 | } |
32 | | |
33 | | #[inline] |
34 | 0 | fn reset(&mut self, checkpoint: Self::Checkpoint) -> Result<(), Self::Error> { |
35 | 0 | self.stream.reset(checkpoint) |
36 | 0 | } |
37 | | } |
38 | | |
39 | | impl<S, U> StreamOnce for Stream<S, U> |
40 | | where |
41 | | S: StreamOnce, |
42 | | { |
43 | | type Token = S::Token; |
44 | | type Range = S::Range; |
45 | | type Position = S::Position; |
46 | | type Error = S::Error; |
47 | | |
48 | | #[inline] |
49 | 0 | fn uncons(&mut self) -> Result<S::Token, StreamErrorFor<Self>> { |
50 | 0 | self.stream.uncons() |
51 | 0 | } |
52 | | |
53 | 0 | fn is_partial(&self) -> bool { |
54 | 0 | self.stream.is_partial() |
55 | 0 | } |
56 | | } |
57 | | |
58 | | impl<S, U> RangeStreamOnce for Stream<S, U> |
59 | | where |
60 | | S: RangeStreamOnce, |
61 | | { |
62 | | #[inline] |
63 | 0 | fn uncons_range(&mut self, size: usize) -> Result<Self::Range, StreamErrorFor<Self>> { |
64 | 0 | self.stream.uncons_range(size) |
65 | 0 | } |
66 | | |
67 | | #[inline] |
68 | 0 | fn uncons_while<F>(&mut self, f: F) -> Result<Self::Range, StreamErrorFor<Self>> |
69 | 0 | where |
70 | 0 | F: FnMut(Self::Token) -> bool, |
71 | | { |
72 | 0 | self.stream.uncons_while(f) |
73 | 0 | } |
74 | | |
75 | 0 | fn uncons_while1<F>(&mut self, f: F) -> ParseResult<Self::Range, StreamErrorFor<Self>> |
76 | 0 | where |
77 | 0 | F: FnMut(Self::Token) -> bool, |
78 | | { |
79 | 0 | self.stream.uncons_while1(f) |
80 | 0 | } |
81 | | |
82 | | #[inline] |
83 | 0 | fn distance(&self, end: &Self::Checkpoint) -> usize { |
84 | 0 | self.stream.distance(end) |
85 | 0 | } |
86 | | |
87 | | #[inline] |
88 | 0 | fn range(&self) -> Self::Range { |
89 | 0 | self.stream.range() |
90 | 0 | } |
91 | | } |