pub struct StringReader<'a> { /* private fields */ }
Expand description
String reader.
Implementations§
Source§impl<'a> StringReader<'a>
impl<'a> StringReader<'a>
Sourcepub fn new<T>(input: &'a T) -> Self
pub fn new<T>(input: &'a T) -> Self
Create a new reader for a given input.
§Arguments
input
- input string or an object that can be referenced as a string
Sourcepub fn current_char(&self) -> Option<char>
pub fn current_char(&self) -> Option<char>
Get the current character (if any) without advancing the input.
Sourcepub fn read_char(&mut self) -> Result<char, ParseError>
pub fn read_char(&mut self) -> Result<char, ParseError>
Get the next character or return an error if the input is empty.
Sourcepub fn match_char(&mut self, expected: char) -> Result<(), ParseError>
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
Sourcepub fn skip_whitespace(&mut self)
pub fn skip_whitespace(&mut self)
Skip all whitespace characters.
Sourcepub fn match_str(&mut self, val: &str) -> Result<(), ParseError>
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
Sourcepub fn read_until<F>(&mut self, cnd: F) -> &'a str
pub fn read_until<F>(&mut self, cnd: F) -> &'a str
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
Sourcepub fn read_word(&mut self) -> &'a str
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).
Sourcepub fn parse_word<T>(&mut self) -> Result<T, T::Err>where
T: FromStr,
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.
Sourcepub fn read_i8(&mut self) -> Result<i8, ParseIntError>
pub fn read_i8(&mut self) -> Result<i8, ParseIntError>
Read a decimal integer as i8.
Sourcepub fn read_u8(&mut self) -> Result<u8, ParseIntError>
pub fn read_u8(&mut self) -> Result<u8, ParseIntError>
Read a decimal integer as u8.
Sourcepub fn read_i16(&mut self) -> Result<i16, ParseIntError>
pub fn read_i16(&mut self) -> Result<i16, ParseIntError>
Read a decimal integer as i16.
Sourcepub fn read_u16(&mut self) -> Result<u16, ParseIntError>
pub fn read_u16(&mut self) -> Result<u16, ParseIntError>
Read a decimal integer as u16.
Sourcepub fn read_i32(&mut self) -> Result<i32, ParseIntError>
pub fn read_i32(&mut self) -> Result<i32, ParseIntError>
Read a decimal integer as i32.
Sourcepub fn read_u32(&mut self) -> Result<u32, ParseIntError>
pub fn read_u32(&mut self) -> Result<u32, ParseIntError>
Read a decimal integer as u32.
Sourcepub fn read_i64(&mut self) -> Result<i64, ParseIntError>
pub fn read_i64(&mut self) -> Result<i64, ParseIntError>
Read a decimal integer as i64.
Sourcepub fn read_u64(&mut self) -> Result<u64, ParseIntError>
pub fn read_u64(&mut self) -> Result<u64, ParseIntError>
Read a decimal integer as u64.
Sourcepub fn read_i128(&mut self) -> Result<i128, ParseIntError>
pub fn read_i128(&mut self) -> Result<i128, ParseIntError>
Read a decimal integer as i128.
Sourcepub fn read_u128(&mut self) -> Result<u128, ParseIntError>
pub fn read_u128(&mut self) -> Result<u128, ParseIntError>
Read a decimal integer as u128.
Sourcepub fn read_isize(&mut self) -> Result<isize, ParseIntError>
pub fn read_isize(&mut self) -> Result<isize, ParseIntError>
Read a decimal integer as isize.
Sourcepub fn read_usize(&mut self) -> Result<usize, ParseIntError>
pub fn read_usize(&mut self) -> Result<usize, ParseIntError>
Read a decimal integer as usize.
Sourcepub fn read_f32(&mut self) -> Result<f32, ParseFloatError>
pub fn read_f32(&mut self) -> Result<f32, ParseFloatError>
Read a floating point number as f32.
Sourcepub fn read_f64(&mut self) -> Result<f64, ParseFloatError>
pub fn read_f64(&mut self) -> Result<f64, ParseFloatError>
Read a floating point number as f64.