Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,15 @@ impl Parser {
}

/// An iterator that parses VT sequences into input events.
///
/// Can't implement [`Iterator`], because this is a "lending iterator".
pub struct Stream<'parser, 'vt, 'input> {
parser: &'parser mut Parser,
stream: vt::Stream<'vt, 'input>,
}

impl<'input> Stream<'_, '_, 'input> {
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Option<Input<'input>> {
impl<'input> Iterator for Stream<'_, '_, 'input> {
type Item = Input<'input>;

fn next(&mut self) -> Option<Input<'input>> {
loop {
if self.parser.bracketed_paste {
return self.handle_bracketed_paste();
Expand Down Expand Up @@ -489,7 +488,9 @@ impl<'input> Stream<'_, '_, 'input> {
}
}
}
}

impl<'input> Stream<'_, '_, 'input> {
/// Once we encounter the start of a bracketed paste
/// we seek to the end of the paste in this function.
///
Expand Down
17 changes: 9 additions & 8 deletions src/vt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Our VT parser.

use std::{mem, time};
use std::time;

use crate::simd::memchr2;

Expand Down Expand Up @@ -114,7 +114,7 @@ pub struct Stream<'parser, 'input> {
off: usize,
}

impl<'parser, 'input> Stream<'parser, 'input> {
impl<'input> Stream<'_, 'input> {
/// Returns the input that is being parsed.
pub fn input(&self) -> &'input str {
self.input
Expand All @@ -136,11 +136,12 @@ impl<'parser, 'input> Stream<'parser, 'input> {
}

/// Parses the next VT sequence from the previously given input.
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Option<Token<'parser, 'input>> {
// I don't know how to tell Rust that `self.parser` and its lifetime
// `'parser` outlives `self`, and at this point I don't care.
let parser = unsafe { mem::transmute::<_, &'parser mut Parser>(&mut *self.parser) };
#[allow(
clippy::should_implement_trait,
reason = "can't implement Iterator because this is a lending iterator"
)]
pub fn next(&mut self) -> Option<Token<'_, 'input>> {
let parser = &mut *self.parser;
let input = self.input;
let bytes = input.as_bytes();

Expand Down Expand Up @@ -242,7 +243,7 @@ impl<'parser, 'input> Stream<'parser, 'input> {
if parser.csi.param_count != 0 || parser.csi.params[0] != 0 {
parser.csi.param_count += 1;
}
return Some(Token::Csi(&parser.csi as &'parser Csi));
return Some(Token::Csi(&parser.csi));
}
b';' => parser.csi.param_count += 1,
b'<'..=b'?' => parser.csi.private_byte = c as char,
Expand Down