Reader

Struct Reader 

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

Struct that allows formated reading.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn read_to(&mut self, s: &mut String, max: usize) -> Result<(), ArgError>

Read at most max chars to the given string.

Source

pub fn read_all(&mut self, s: &mut String) -> Result<(), ArgError>

Read all the remaining chars to the given string.

Source

pub fn pos(&self) -> usize

Get the position of the last returned char.

Source

pub fn bytes_size_hint(&self) -> usize

Gets the low estimate of the remaining bytes.

Source

pub fn map_err(&self, e: ArgError) -> ArgError

Adds relevant information to the given error.

Source

pub fn err_parse(&self, msg: impl Into<Cow<'static, str>>) -> ArgError

Creates parse error with the given message.

Source

pub fn err_value(&self, msg: impl Into<Cow<'static, str>>) -> ArgError

Creates value error with the given message.

Source

pub fn map_err_peek(&self, e: ArgError) -> ArgError

Adds relevant information to the given error. The span will start at the next character.

Source

pub fn err_parse_peek(&self, msg: impl Into<Cow<'static, str>>) -> ArgError

Creates parse error with the given message. Span will start at the next character.

Source

pub fn err_value_peek(&self, msg: impl Into<Cow<'static, str>>) -> ArgError

Creates value error with the given message. Span will start at the next character.

Source

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

Peek at the next character.

Source

pub fn expect(&mut self, s: &str) -> Result<(), ArgError>

Match the given string to the output. If it doesn’t match, return error.

Source

pub fn skip_while( &mut self, f: impl FnMut(char) -> bool, ) -> Result<(), ArgError>

Skips characters while the given function matches.

Source

pub fn is_next_some(&mut self, c: char) -> Result<bool, ArgError>

Checks if the next char is the given char. If yes, returns true and moves to the next position.

Source

pub fn is_next( &mut self, p: impl FnOnce(Option<char>) -> bool, ) -> Result<bool, ArgError>

Checks if the next value matches the predicate. If yes, returns true and moves to the next position.

Source

pub fn next(&mut self) -> Result<Option<char>, ArgError>

Gets the next character.

Source

pub fn chars(&mut self) -> ReaderChars<'_, 'a>

Gets iterator over chars.

Source

pub fn parse<'f, T>( &mut self, fmt: &'f ReadFmt<'f>, ) -> Result<(T, Option<ArgError>), ArgError>
where T: FromRead,

Parses the next value.

Source

pub fn trim_left(&mut self, fmt: &ReadFmt<'_>) -> Result<(), ArgError>

Trims characters from the left side according to the given format.

Source

pub fn trim_right(&mut self, fmt: &ReadFmt<'_>) -> Result<(), ArgError>

Trims characters from the right side according to the given format.

Source

pub fn unnext(&mut self, c: char)

Prepends the given character to the reader.

Source

pub fn prepend<I>(&mut self, s: I)

Prepends the given characters to the reader.

Trait Implementations§

Source§

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

Source§

fn from(value: &'a str) -> Reader<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Box<dyn Iterator<Item = Result<char, ArgError>> + 'a>> for Reader<'a>

Source§

fn from( value: Box<dyn Iterator<Item = Result<char, ArgError>> + 'a>, ) -> Reader<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Box<dyn Iterator<Item = char> + 'a>> for Reader<'a>

Source§

fn from(value: Box<dyn Iterator<Item = char> + 'a>) -> Reader<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Box<dyn Read + 'a>> for Reader<'a>

Source§

fn from(value: Box<dyn Read + 'a>) -> Reader<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Cow<'a, str>> for Reader<'a>

Source§

fn from(value: Cow<'a, str>) -> Reader<'a>

Converts to this type from the input type.
Source§

impl From<String> for Reader<'_>

Source§

fn from(value: String) -> Reader<'_>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> !RefUnwindSafe for Reader<'a>

§

impl<'a> !Send for Reader<'a>

§

impl<'a> !Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> !UnwindSafe for Reader<'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> Scale<T> for T

Source§

fn scale(self) -> T

Scale this type to the given other type.
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.