// Copyright (c) 2016-2021 Fabian Schuiki use crate::grind::Grinder; use std; pub struct Peekable { inner: T, peek: T::Item, } impl Peekable where T: Grinder, { pub fn new(mut inner: T) -> Peekable { let peek = inner.next(); Peekable { inner: inner, peek: peek, } } pub fn peek(&self) -> &T::Item { &self.peek } } impl Grinder for Peekable where T: Grinder, { type Item = T::Item; type Error = T::Error; fn emit(&mut self, err: Self::Error) { self.inner.emit(err) } fn next(&mut self) -> Self::Item { let mut n = self.inner.next(); std::mem::swap(&mut self.peek, &mut n); n } } impl From for Peekable where T: Grinder, { fn from(inner: T) -> Peekable { Peekable::new(inner) } }