Struct StringReader

Source
pub struct StringReader<'a> { /* private fields */ }
Expand description

String reader.

Implementations§

Source§

impl<'a> StringReader<'a>

Source

pub fn new<T>(input: &'a T) -> Self
where T: AsRef<str> + ?Sized,

Create a new reader for a given input.

§Arguments
  • input - input string or an object that can be referenced as a string
Source

pub fn current_char(&self) -> Option<char>

Get the current character (if any) without advancing the input.

Source

pub fn read_char(&mut self) -> Result<char, ParseError>

Get the next character or return an error if the input is empty.

Source

pub fn match_char(&mut self, expected: char) -> Result<(), ParseError>

Match a given character to the input and, if successful, advance the input by exactly one character. An error is returned if the input character does not match with the given one or if the input is empty.

§Arguments
  • expected - expected character
Source

pub fn skip_char(&mut self)

Skip one character.

Source

pub fn skip_whitespace(&mut self)

Skip all whitespace characters.

Source

pub fn match_str(&mut self, val: &str) -> Result<(), ParseError>

Match a given string to the input and, if successful, advance the input by the length of the given string. An error is returned if the input does not start with the given string.

§Arguments
  • val - expected string
Source

pub fn read_until<F>(&mut self, cnd: F) -> &'a str
where F: FnMut(char) -> bool,

Read until a given condition is true or until the end of the input and return the string.

§Arguments
  • cnd - a closure that takes a single character and returns true/false
Source

pub fn read_word(&mut self) -> &'a str

Read one word from the input and return it. A word ends with the first whitespace character or with the end of the input. The method skips all initial whitespace characters (if any).

Source

pub fn parse_word<T>(&mut self) -> Result<T, T::Err>
where T: FromStr,

Read the next word and parse it. The input won’t be advanced if the word cannot be parsed.

Source

pub fn read_i8(&mut self) -> Result<i8, ParseIntError>

Read a decimal integer as i8.

Source

pub fn read_u8(&mut self) -> Result<u8, ParseIntError>

Read a decimal integer as u8.

Source

pub fn read_i16(&mut self) -> Result<i16, ParseIntError>

Read a decimal integer as i16.

Source

pub fn read_u16(&mut self) -> Result<u16, ParseIntError>

Read a decimal integer as u16.

Source

pub fn read_i32(&mut self) -> Result<i32, ParseIntError>

Read a decimal integer as i32.

Source

pub fn read_u32(&mut self) -> Result<u32, ParseIntError>

Read a decimal integer as u32.

Source

pub fn read_i64(&mut self) -> Result<i64, ParseIntError>

Read a decimal integer as i64.

Source

pub fn read_u64(&mut self) -> Result<u64, ParseIntError>

Read a decimal integer as u64.

Source

pub fn read_i128(&mut self) -> Result<i128, ParseIntError>

Read a decimal integer as i128.

Source

pub fn read_u128(&mut self) -> Result<u128, ParseIntError>

Read a decimal integer as u128.

Source

pub fn read_isize(&mut self) -> Result<isize, ParseIntError>

Read a decimal integer as isize.

Source

pub fn read_usize(&mut self) -> Result<usize, ParseIntError>

Read a decimal integer as usize.

Source

pub fn read_f32(&mut self) -> Result<f32, ParseFloatError>

Read a floating point number as f32.

Source

pub fn read_f64(&mut self) -> Result<f64, ParseFloatError>

Read a floating point number as f64.

Source

pub fn is_empty(&self) -> bool

Check if the reader is empty.

Source

pub fn as_str(&self) -> &'a str

Get the rest of the input.

Auto Trait Implementations§

§

impl<'a> Freeze for StringReader<'a>

§

impl<'a> RefUnwindSafe for StringReader<'a>

§

impl<'a> Send for StringReader<'a>

§

impl<'a> Sync for StringReader<'a>

§

impl<'a> Unpin for StringReader<'a>

§

impl<'a> UnwindSafe for StringReader<'a>

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.