pub struct Peeking<'a, T, S, E> {
pub start: S,
pub end: E,
pub end_slice: usize,
pub data: &'a [T],
}Expand description
A successful peeking result.
A Peeking contains the start and end results of a successful peek, the
length of the end slice, and a reference to the data that was peeked.
Fields§
§start: SThe start of the match.
end: EThe end of the match.
end_slice: usizeThe length of peeked slice.
data: &'a [T]The data that was peeked.
Implementations§
Source§impl<'a, T, S, E> Peeking<'a, T, S, E>
impl<'a, T, S, E> Peeking<'a, T, S, E>
Sourcepub fn peeked_slice(&self) -> &'a [T]
pub fn peeked_slice(&self) -> &'a [T]
Get a slice of the data that was peeked.
Examples found in repository?
More examples
examples/expression.rs (line 172)
164 fn accept(scanner: &mut Scanner<'a, u8>) -> ParseResult<Self> {
165 OptionalWhitespaces::accept(scanner)?;
166 // Check if there is a parenthesis
167 let result = peek(GroupKind::Parenthesis, scanner)?;
168
169 match result {
170 Some(peeked) => {
171 // Parse the inner expression
172 let mut inner_scanner = Scanner::new(peeked.peeked_slice());
173 let inner_result = Expression::accept(&mut inner_scanner)?;
174 scanner.bump_by(peeked.end_slice);
175 Ok(inner_result)
176 }
177 None => {
178 // Parse the reduced expression or the right expression
179 let accepted = Acceptor::new(scanner)
180 .try_or(ExpressionInternal::RightExpression)?
181 .try_or(ExpressionInternal::Reducted)?
182 .finish()
183 .ok_or(ParseError::UnexpectedToken)?;
184
185 Ok(accepted.into())
186 }
187 }
188 }Trait Implementations§
impl<'a, T, S, E> StructuralPartialEq for Peeking<'a, T, S, E>
Auto Trait Implementations§
impl<'a, T, S, E> Freeze for Peeking<'a, T, S, E>
impl<'a, T, S, E> RefUnwindSafe for Peeking<'a, T, S, E>
impl<'a, T, S, E> Send for Peeking<'a, T, S, E>
impl<'a, T, S, E> Sync for Peeking<'a, T, S, E>
impl<'a, T, S, E> Unpin for Peeking<'a, T, S, E>
impl<'a, T, S, E> UnwindSafe for Peeking<'a, T, S, E>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more