UserPosn

Trait UserPosn 

Source
pub trait UserPosn:
    Sized
    + Debug
    + Copy
    + Default
    + PartialEq
    + Eq
    + Hash {
    // Provided methods
    fn advance_cols(self, _num_bytes: usize, _num_chars: usize) -> Self { ... }
    fn advance_line(self, _num_bytes: usize) -> Self { ... }
    fn line(&self) -> usize { ... }
    fn column(&self) -> usize { ... }
    fn error_fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> { ... }
}
Expand description

Trait for location within a stream

This base trait is used to enable tracking the position of a token parser within a stream in a manner that is useful for human-readable error messages

A simple implementation can be null, if the position is not critical for error messages for the token parser - for example, parsing a simple string in a test.

For a single file implementation see crate::LineColumn

Provided Methods§

Source

fn advance_cols(self, _num_bytes: usize, _num_chars: usize) -> Self

Advance the state of the stream by a number of bytes and a number of characters; the characters are guaranteed to not be newlines

For character streams (where num_bytes is not the same as num_char) this must only be invoked to move on to a new UTF8 character boundary - hence num_bytes must be a (sum of) len_utf8 values for the text at byte offset of self.

Source

fn advance_line(self, _num_bytes: usize) -> Self

Advance the state of the stream by a number of bytes and to the start of the next line

For character streams this must only be invoked to move on to a new UTF8 character boundary - hence num_bytes must be a (sum of) len_utf8 values for the text at byte offset of self, the last character of which is a newline

Source

fn line(&self) -> usize

Return the line number (if supported, else 0)

Source

fn column(&self) -> usize

Return the column number (if supported, else 0)

Source

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

Format self for an error - this can be the same format as Display (if implemented), or Debug, or whatever is desired

It is required for a Lexer to generate a fail-to-parse-character error

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl UserPosn for ()

Source§

impl UserPosn for usize

Source§

fn advance_cols(self, byte_ofs: usize, _num_chars: usize) -> Self

Source§

fn advance_line(self, byte_ofs: usize) -> Self

Implementors§