Struct Reader

Source
pub struct Reader<T, const BUFFER_SIZE: usize = BYTE_BUFFER_SIZE> { /* private fields */ }
Expand description

A generic UTF-8 character reader for lexers.

The generic parameter BUFFER_SIZE specifies the size of the internal buffer of Reader.

Reader always tries to read UTF-8 characters from the stream. If there are no valid UTF-8 characters, Reader will return a fatal error (Error::Fatal).

Implementations§

Source§

impl<T, const BUFFER_SIZE: usize> Reader<T, BUFFER_SIZE>

Source

pub fn new(reader: T, file_type: FileType) -> Self

Creates a new reader with the given inner reader and file type.

Source§

impl<T> Reader<T>

Source

pub fn into_inner(self) -> T

Converts the reader into its inner reader.

Source§

impl Reader<File>

Source

pub fn from_path<P>(path: P) -> Result<Self>
where P: AsRef<Path> + Clone,

Creates a new reader from the file at the given path.

Source§

impl Reader<Stdin>

Source

pub fn from_stdin() -> Self

Creates a new reader from the standard input.

Trait Implementations§

Source§

impl<'a> From<&'a [u8]> for Reader<&'a [u8]>

Source§

fn from(b: &'a [u8]) -> Self

Creates a new reader from the given &[u8].

Source§

impl<'a> From<&'a str> for Reader<Cursor<&'a str>>

Source§

fn from(s: &'a str) -> Self

Creates a new reader from the given &str.

Source§

impl From<Stdin> for Reader<Stdin>

Source§

fn from(stdin: Stdin) -> Self

Creates a new reader from the standard input.

Source§

impl From<String> for Reader<Cursor<String>>

Source§

fn from(s: String) -> Self

Creates a new reader from the given String.

Source§

impl<T> InputStream for Reader<T>
where T: Read,

Source§

type CharType = char

The type of the character produced by the input stream.
Source§

fn next_char_loc(&mut self) -> Result<(Option<char>, Location)>

Reads the next character from the input stream. Read more
Source§

fn unread(&mut self, last: (Option<char>, Location))

Unreads the given character and the last location and put it back to the input stream.
Source§

fn span(&self) -> &Span

Returns a reference to the current span in the lexer.
Source§

fn set_line_col(&mut self, line: u32, col: u32)

Sets the line and column of the current span. Read more
Source§

fn peek(&mut self) -> Result<Option<char>>

Peeks the next character from the input stream. Read more
Source§

fn peek_with_span(&mut self) -> Result<(Option<char>, Span)>

Peeks the next character from the input stream. Returns the peeked character and its span. Read more
Source§

fn next_char(&mut self) -> Result<Option<Self::CharType>>

Reads the next character from the input stream. Read more
Source§

fn next_char_span(&mut self) -> Result<(Option<Self::CharType>, Span)>

Reads the next character from the input stream. Read more
Source§

fn next_span(&mut self) -> Result<&Span>

Reads the next character from the input stream. Read more
Source§

fn skip_until<F>(&mut self, f: F) -> Result<()>
where Self::CharType: Clone, F: FnMut(Self::CharType) -> bool,

Skips characters until a character specified by the predicate is encountered.
Source§

fn collect_until<F>(&mut self, f: F) -> Result<Vec<Self::CharType>>
where Self::CharType: Clone, F: FnMut(&Self::CharType) -> bool,

Collects characters into a vector until a character specified by the predicate is encountered.
Source§

fn collect_with_span_until<F>( &mut self, f: F, ) -> Result<(Vec<Self::CharType>, Span)>
where Self::CharType: Clone, F: FnMut(&Self::CharType) -> bool,

Collects characters into a vector until a character specified by the predicate is encountered. Read more

Auto Trait Implementations§

§

impl<T, const BUFFER_SIZE: usize> Freeze for Reader<T, BUFFER_SIZE>
where T: Freeze,

§

impl<T, const BUFFER_SIZE: usize> RefUnwindSafe for Reader<T, BUFFER_SIZE>
where T: RefUnwindSafe,

§

impl<T, const BUFFER_SIZE: usize> Send for Reader<T, BUFFER_SIZE>
where T: Send,

§

impl<T, const BUFFER_SIZE: usize> Sync for Reader<T, BUFFER_SIZE>
where T: Sync,

§

impl<T, const BUFFER_SIZE: usize> Unpin for Reader<T, BUFFER_SIZE>
where T: Unpin,

§

impl<T, const BUFFER_SIZE: usize> UnwindSafe for Reader<T, BUFFER_SIZE>
where T: UnwindSafe,

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.