Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'alloc>(/* private fields */);
Expand description

OSC (Operating System Command) sequence parser and command handling.

The parser operates in a streaming fashion, processing input byte-by-byte to handle OSC sequences that may arrive in fragments across multiple reads. This interface makes it easy to integrate into most environments and avoids over-allocating buffers.

Implementations§

Source§

impl<'alloc> Parser<'alloc>

Source

pub fn new() -> Result<Self>

Create a new OSC parser.

Source

pub fn new_with_alloc<'ctx: 'alloc, Ctx>( alloc: &'alloc Allocator<'ctx, Ctx>, ) -> Result<Self>

Create a new OSC parser with a custom allocator.

See the crate-level documentation regarding custom memory management and lifetimes.

Source

pub fn reset(&mut self)

Reset an OSC parser instance to its initial state.

Resets the parser state, clearing any partially parsed OSC sequences and returning the parser to its initial state. This is useful for reusing a parser instance or recovering from parse errors.

Source

pub fn next_byte(&mut self, byte: u8)

Parse the next byte in an OSC sequence.

Processes a single byte as part of an OSC sequence. The parser maintains internal state to track the progress through the sequence. Call this function for each byte in the sequence data.

When finished pumping the parser with bytes, call Parser::end to get the final result.

Source

pub fn end<'p>(&'p mut self, terminator: u8) -> Command<'p, 'alloc>

Finalize OSC parsing and retrieve the parsed command.

Call this function after feeding all bytes of an OSC sequence to the parser using Parser::next_byte with the exception of the terminating character (ESC or ST). This function finalizes the parsing process and returns the parsed OSC command. Invalid commands will return a command with type CommandType::Invalid.

The terminator parameter specifies the byte that terminated the OSC sequence (typically 0x07 for BEL or 0x5C for ST after ESC). This information is preserved in the parsed command so that responses can use the same terminator format for better compatibility with the calling program. For commands that do not require a response, this parameter is ignored and the resulting command will not retain the terminator information.

Trait Implementations§

Source§

impl<'alloc> Debug for Parser<'alloc>

Source§

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

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

impl Drop for Parser<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'alloc> Freeze for Parser<'alloc>

§

impl<'alloc> RefUnwindSafe for Parser<'alloc>

§

impl<'alloc> !Send for Parser<'alloc>

§

impl<'alloc> !Sync for Parser<'alloc>

§

impl<'alloc> Unpin for Parser<'alloc>

§

impl<'alloc> UnsafeUnpin for Parser<'alloc>

§

impl<'alloc> UnwindSafe for Parser<'alloc>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.