Struct DefLine

Source
pub struct DefLine<I, FILE = NoFile> { /* private fields */ }
Expand description

A positioned iterator

When I is a char iterator DefLine<I, FILE> provides the method DefLine::next_pos that returns the next available positioned character as Pos<Option<char>, FILE> by calling I::next.

Implementations§

Source§

impl<I, F> DefLine<I, F>

Source

pub fn map_iter<J, MF: FnOnce(I) -> J>(self, f: MF) -> DefLine<J, F>

Applies f to the inner iterator iter of type I inside self to get a new DefLine with f(iter) as iter.

Source

pub fn map_iter_reset<J, MF: FnOnce(I) -> J>(self, f: MF) -> DefLine<J, F>

Like DefLine::map_iter but also resets the position to the beginning.

Source§

impl<I, F> DefLine<I, F>
where I: Iterator<Item = char>, F: Default + Clone,

Source

pub fn new<J: IntoIterator<IntoIter = I>>(it: J) -> Self

Like DefLine::new_file but with F::default() as file.

Source§

impl<I, F> DefLine<I, F>
where I: Iterator<Item = char>, F: Clone,

Source

pub fn new_file<J>(it: J, f: F) -> Self
where J: IntoIterator<IntoIter = I>,

Creates a new DefLine with the specified iterator and file.

Source

pub fn peekable(self) -> DefLine<Peekable<I>, F>

Same as self.map_iter(I::peekable)

Source

pub fn next_pos(&mut self) -> Pos<Option<char>, F>

Advances the iterator and returns the next positioned value.

When the iterator has finished the returned position follows the one that has been returned by the last character.

Source

pub fn dig_char_cf<T, MF: FnMut(char) -> ControlFlow<T>>( &mut self, f: MF, ) -> Pos<Option<T>, F>

Discards characters as long as Self::next_pos returns Some(ch) and f(ch) returns ControlFlow::Continue.

When f(ch) returns ControlFlow::Break(t) then this function will return Some(t).

Source

pub fn dig_char_until<MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<Option<char>, F>

Like DefLine::dig_char_cf but discards characters as long as f returns true.

Source

pub fn next_no_spaces(&mut self) -> Pos<Option<char>, F>

Gets the first not-whitespace character.

Removes any whitespace according to predicates::is_whitespace.

Source

pub fn next_nl_no_spaces(&mut self) -> Pos<Option<char>, F>

As Self::next_no_spaces but threats the \n character as not whitespace.

Source

pub fn append_delim_cf<V: Appender<K>, K, Z, MF: FnMut(char) -> ControlFlow<Z, K>>( &mut self, f: MF, ) -> (Pos<V, F>, Pos<Option<Z>, F>)

Appends characters to an accumulator.

Every time Self::next_pos returns Some(ch) and f(ch) returns ControlFlow::Continue(k) then k is pushed into an accumulator of type V. When f(ch) returns instead ControlFlow::Break(z) then both Some(z) and the accumulator are returned.

Notice that, unlike Self::append_cf, ch will always be discarded.

Source

pub fn append_delim_until<V: Appender<char>, MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> (Pos<V, F>, Pos<Option<char>, F>)

Like DefLine::append_delim_cf but appends characters as long as f returns true.

Source

pub fn append_delim_trim_cf<V: AppenderExt<K>, K, Z, SP: FnMut(char) -> bool, CF: FnMut(char) -> ControlFlow<Z, K>>( &mut self, sp: SP, cf: CF, ) -> (Pos<V, F>, Pos<Option<Z>, F>)

Removes leading and trailing characters.

Every character returned by DefLine::next_pos can be considered a space or a nonspace character depending on whether sp returns true or false. Until function cf returns ControlFlow::Continue retrieved characters are stores in a container of type V and when cf returns ControlFlow::Break then leading and trailing spaces are removed from the returned container.

If the returned container is not empty then the returned position is exactly the position of the first nonspace appended character, otherwise it is the position of the first character that terminated the accumulation.

Source

pub fn append_delim_trim_until<V: AppenderExt<char>, SP: FnMut(char) -> bool, CF: FnMut(char) -> bool>( &mut self, sp: SP, cf: CF, ) -> (Pos<V, F>, Pos<Option<char>, F>)

Like Self::append_delim_trim_cf but continue appending characters as long as cf returns true.

Source

pub fn get_line<V: Appender<char>>(&mut self) -> Pos<V, F>

Retrieves a line.

A line is a sequence of characters terminated by a \n character or up to the end of the iterator. Notice that the eventual \n character is discarded and not added to the returned line.

Source

pub fn get_line_trim<V: AppenderExt<char>>(&mut self) -> Pos<V, F>

Gets a line and removes leading and trailing whitespaces.

See also DefLine::append_delim_trim_cf and predicate::is_whitespace for the used definition of whitespace.

Source§

impl<I, F> DefLine<Peekable<I>, F>
where I: Iterator<Item = char>, F: Clone,

Source

pub fn peek_pos(&mut self) -> Pos<Option<char>, F>

Like DefLine::next_pos but doesn’t remove the character from the underlying iterator.

Source

pub fn dig_peek_cf<T, MF: FnMut(char) -> ControlFlow<T>>( &mut self, f: MF, ) -> Pos<Option<T>, F>

Like DefLine::dig_char_cf but when f(ch) returns ControlFlow::Break then ch is not removed from the underlying iterator.

Source

pub fn dig_peek_until<MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<Option<char>, F>

Like DefLine::dig_char_until but when f(ch) returns false then ch is not removed from the underlying iterator.

Source

pub fn discard(&mut self)

Discard the last character in the iterator

Source

pub fn append_cf<V: Appender<K>, K, MF: FnMut(char) -> ControlFlow<(), K>>( &mut self, f: MF, ) -> Pos<V, F>

Appends characters to an accumulator.

Every time DefLine::peek_pos returns Some(ch) and f(ch) returns ControlFlow::Continue(k) then ch is discarded and k is pushed into an accumulator of type V. When f(ch) returns instead ControlFlow::Break then ch is not discarded and the used accumulator is returned.

Source

pub fn append_until<V: Appender<char>, MF: FnMut(char) -> bool>( &mut self, f: MF, ) -> Pos<V, F>

Like DefLine::append_cf but appends characters as long as f returns true.

Moreover, when f(ch) returns true then ch is not discarded from the unerlying iterator.

Source

pub fn append_trim_cf<V: AppenderExt<K>, K, SP: FnMut(char) -> bool, CF: FnMut(char) -> ControlFlow<(), K>>( &mut self, sp: SP, cf: CF, ) -> Pos<V, F>

Removes leading and trailing characters.

Every character returned by DefLine::peek_pos can be considered a space or a nonspace character depending on whether sp returns true or false. Until function cf returns ControlFlow::Continue retrieved characters are stores in a container of type V and when cf returns ControlFlow::Break then leading and trailing spaces are removed from the returned container.

If the returned container is not empty then the returned position is exactly the position of the first nonspace appended character, otherwise it is the position of the first character that terminated the accumulation.

Source

pub fn trim_spaces_until<V: AppenderExt<char>, CF: FnMut(char) -> bool>( &mut self, f: CF, ) -> Pos<V, F>

Removes leading and trailing whitespaces.

See also DefLine::append_trim_cf and predicates::is_whitespace for the used definition of whitespace.

Source

pub fn get_ident<V: Appender<char>>(&mut self) -> Pos<V, F>

Parse an identifier by dircarding leading whitespaces and without changing line.

Gets an identifier defined as a contiguous sequence of alphabetic characters as defined in predicates::is_alphabetic.

Source

pub fn get_num_nonl(&mut self) -> Pos<Option<u32>, F>

Parses a decimal number and removes leading and trailing spaces in the same line.

Source

pub fn peek_spaces(&mut self) -> Pos<Option<char>, F>

Peeks character by discarding whitespaces and newline characters.

Removes any whitespace according to predicates::is_whitespace.

Source

pub fn peek_spaces_nonl(&mut self) -> Pos<Option<char>, F>

Peeks character by whitespaces but not newline characters.

Auto Trait Implementations§

§

impl<I, FILE> Freeze for DefLine<I, FILE>
where I: Freeze, FILE: Freeze,

§

impl<I, FILE> RefUnwindSafe for DefLine<I, FILE>
where I: RefUnwindSafe, FILE: RefUnwindSafe,

§

impl<I, FILE> Send for DefLine<I, FILE>
where I: Send, FILE: Send,

§

impl<I, FILE> Sync for DefLine<I, FILE>
where I: Sync, FILE: Sync,

§

impl<I, FILE> Unpin for DefLine<I, FILE>
where I: Unpin, FILE: Unpin,

§

impl<I, FILE> UnwindSafe for DefLine<I, FILE>
where I: UnwindSafe, FILE: 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.