pub trait Scan: BufRead {
// Required methods
fn in_flight(&self) -> bool;
fn read_token(&mut self) -> Result<Token<'_>>;
// Provided method
fn read_sequence(&mut self, control: Control) -> Result<&[u8]> { ... }
}
Expand description
A scanner for UTF-8 characters and control sequences.
An implementation of this trait provides the state machine necessary for scanning UTF-8 characters and control sequences. Since scanning control sequences requires one byte lookahead, an implementation also buffers the data it reads from the terminal.
Some terminal emulators may require more than one read from terminal input
to consume a complete ANSI escape sequence serving as query response. Hence
Scan::read_token
may perform an arbitrary number of reads from the
underlying input, including none, to recognize a complete control sequence.
However, an implementation must not issue reads after it has started
recognizing a text token. In other words, when reading a text token, the end
of buffered data also is the end of the text token.
This trait is object-safe.
Required Methods§
Sourcefn in_flight(&self) -> bool
fn in_flight(&self) -> bool
Determine if the state machine currently is in-flight.
Using a scanner as a reader is only safe if this method returns false
.
Sourcefn read_token(&mut self) -> Result<Token<'_>>
fn read_token(&mut self) -> Result<Token<'_>>
Read the next token.
If the internal buffer has been exhausted, this method may read from the connection upon invocation. For text tokens, it performs no further reads. That is, a text token always ends with the currently buffered data.
Provided Methods§
Sourcefn read_sequence(&mut self, control: Control) -> Result<&[u8]>
fn read_sequence(&mut self, control: Control) -> Result<&[u8]>
Read the next token as a control sequence.
This method reads the next token and, after making sure it is a control sequence starting with the given control, returns the payload.