Skip to main content

Parser

Struct Parser 

Source
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

Source

pub fn new() -> Self

Creates a parser with conservative default limits.

Examples found in repository?
examples/trace.rs (line 74)
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}
Source

pub fn with_options(options: ParserOptions) -> Self

Creates a parser with caller-selected buffering limits.

Source

pub const fn options(&self) -> ParserOptions

Returns the limits used by this parser.

Source

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?
examples/trace.rs (line 77)
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}
Source

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?
examples/trace.rs (line 79)
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}
Source

pub fn reset(&mut self)

Discards all pending parser state without dispatching an event.

Trait Implementations§

Source§

impl Debug for Parser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Parser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.