pub struct Parser { /* private fields */ }Expand description
An incremental parser for VT control streams.
Parser retains only its current state and bounded control-sequence data.
It does not retain any input slice after Parser::advance returns and can
be moved between threads as ordinary owned Rust state. A handler must have
exclusive mutable access while an input chunk is processed.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a parser with conservative default limits.
Examples found in repository?
70fn main() -> io::Result<()> {
71 let mut input = Vec::new();
72 io::stdin().read_to_end(&mut input)?;
73
74 let mut parser = Parser::new();
75 let mut trace = Trace;
76 for chunk in input.chunks(3) {
77 parser.advance(&mut trace, chunk);
78 }
79 parser.finish(&mut trace);
80 Ok(())
81}Sourcepub fn with_options(options: ParserOptions) -> Self
pub fn with_options(options: ParserOptions) -> Self
Creates a parser with caller-selected buffering limits.
Sourcepub const fn options(&self) -> ParserOptions
pub const fn options(&self) -> ParserOptions
Returns the limits used by this parser.
Sourcepub fn advance<H: Handler + ?Sized>(&mut self, handler: &mut H, bytes: &[u8])
pub fn advance<H: Handler + ?Sized>(&mut self, handler: &mut H, bytes: &[u8])
Feeds a chunk of bytes to the parser.
A chunk may end in the middle of a UTF-8 scalar, ESC/CSI sequence, or control string. Events are delivered synchronously and borrow parser storage only for the duration of the handler callback.
Examples found in repository?
70fn main() -> io::Result<()> {
71 let mut input = Vec::new();
72 io::stdin().read_to_end(&mut input)?;
73
74 let mut parser = Parser::new();
75 let mut trace = Trace;
76 for chunk in input.chunks(3) {
77 parser.advance(&mut trace, chunk);
78 }
79 parser.finish(&mut trace);
80 Ok(())
81}Sourcepub fn finish<H: Handler + ?Sized>(&mut self, handler: &mut H)
pub fn finish<H: Handler + ?Sized>(&mut self, handler: &mut H)
Finishes the current stream.
An incomplete UTF-8 scalar produces one U+FFFD replacement character. Incomplete or cancelled control sequences are discarded, including unterminated control strings. The parser is left in the ground state and may immediately receive another stream.
Examples found in repository?
70fn main() -> io::Result<()> {
71 let mut input = Vec::new();
72 io::stdin().read_to_end(&mut input)?;
73
74 let mut parser = Parser::new();
75 let mut trace = Trace;
76 for chunk in input.chunks(3) {
77 parser.advance(&mut trace, chunk);
78 }
79 parser.finish(&mut trace);
80 Ok(())
81}