Skip to content

Commit 35b5c50

Browse files
committed
Implemented ValueInput for IterInput
1 parent 6613907 commit 35b5c50

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

src/inspector.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ impl<'src, T: Clone, I: Input<'src>> Inspector<'src, I> for RollbackState<T> {
9292
#[inline(always)]
9393
fn on_token(&mut self, _: &<I as Input<'src>>::Token) {}
9494
#[inline(always)]
95-
fn on_save<'parse>(&self, _: &Cursor<'src, 'parse, I>) -> Self::Checkpoint { self.0.clone() }
95+
fn on_save<'parse>(&self, _: &Cursor<'src, 'parse, I>) -> Self::Checkpoint {
96+
self.0.clone()
97+
}
9698
#[inline(always)]
97-
fn on_rewind<'parse>(&mut self, cp: &Checkpoint<'src, 'parse, I, Self::Checkpoint>) { self.0 = cp.inspector.clone(); }
99+
fn on_rewind<'parse>(&mut self, cp: &Checkpoint<'src, 'parse, I, Self::Checkpoint>) {
100+
self.0 = cp.inspector.clone();
101+
}
98102
}
99103

100104
impl<T> Deref for RollbackState<T> {
@@ -127,9 +131,13 @@ impl<'src, T: Clone, I: Input<'src>> Inspector<'src, I> for TruncateState<T> {
127131
#[inline(always)]
128132
fn on_token(&mut self, _: &<I as Input<'src>>::Token) {}
129133
#[inline(always)]
130-
fn on_save<'parse>(&self, _: &Cursor<'src, 'parse, I>) -> Self::Checkpoint { self.0.len() }
134+
fn on_save<'parse>(&self, _: &Cursor<'src, 'parse, I>) -> Self::Checkpoint {
135+
self.0.len()
136+
}
131137
#[inline(always)]
132-
fn on_rewind<'parse>(&mut self, cp: &Checkpoint<'src, 'parse, I, Self::Checkpoint>) { self.0.truncate(cp.inspector); }
138+
fn on_rewind<'parse>(&mut self, cp: &Checkpoint<'src, 'parse, I, Self::Checkpoint>) {
139+
self.0.truncate(cp.inspector);
140+
}
133141
}
134142

135143
impl<T> Deref for TruncateState<T> {

src/stream.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub type BoxedStream<'a, T> = Stream<Box<dyn Iterator<Item = T> + 'a>>;
6363
pub type BoxedExactSizeStream<'a, T> = Stream<Box<dyn ExactSizeIterator<Item = T> + 'a>>;
6464

6565
impl<I: Iterator> Sealed for Stream<I> {}
66-
impl<'a, I: Iterator + 'a> Input<'a> for Stream<I>
66+
impl<'src, I: Iterator + 'src> Input<'src> for Stream<I>
6767
where
6868
I::Item: Clone,
6969
{
@@ -100,7 +100,7 @@ where
100100
}
101101
}
102102

103-
impl<'a, I: ExactSizeIterator + 'a> ExactSizeInput<'a> for Stream<I>
103+
impl<'src, I: ExactSizeIterator + 'src> ExactSizeInput<'src> for Stream<I>
104104
where
105105
I::Item: Clone,
106106
{
@@ -110,7 +110,7 @@ where
110110
}
111111
}
112112

113-
impl<'a, I: Iterator + 'a> ValueInput<'a> for Stream<I>
113+
impl<'src, I: Iterator + 'src> ValueInput<'src> for Stream<I>
114114
where
115115
I::Item: Clone,
116116
{
@@ -191,6 +191,28 @@ where
191191
}
192192
}
193193

194+
// impl<'src, I, S> ExactSizeInput<'src> for IterInput<I, S>
195+
// where
196+
// I: Iterator<Item = (T, S)> + Clone + 'src,
197+
// S: Span + 'src,
198+
// {
199+
// #[inline(always)]
200+
// unsafe fn span_from(this: &mut Self::Cache, range: RangeFrom<&Self::Cursor>) -> Self::Span {
201+
// (*range.start..this.tokens.len() + cursor.0.len()).into()
202+
// }
203+
// }
204+
205+
impl<'src, I, T: 'src, S> ValueInput<'src> for IterInput<I, S>
206+
where
207+
I: Iterator<Item = (T, S)> + Clone + 'src,
208+
S: Span + 'src,
209+
{
210+
#[inline]
211+
unsafe fn next(this: &mut Self::Cache, cursor: &mut Self::Cursor) -> Option<Self::Token> {
212+
Self::next_maybe(this, cursor)
213+
}
214+
}
215+
194216
#[test]
195217
fn map_tuple() {
196218
fn parser<'src, I: Input<'src, Token = char>>() -> impl Parser<'src, I, char> {

0 commit comments

Comments
 (0)