Trait Input

Source
pub trait Input {
Show 32 methods // Required methods fn lookahead(&mut self, count: usize); fn buflen(&self) -> usize; fn bufmaxlen(&self) -> usize; fn raw_read_ch(&mut self) -> char; fn raw_read_non_breakz_ch(&mut self) -> Option<char>; fn skip(&mut self); fn skip_n(&mut self, count: usize); fn peek(&self) -> char; fn peek_nth(&self, n: usize) -> char; // Provided methods fn buf_is_empty(&self) -> bool { ... } fn look_ch(&mut self) -> char { ... } fn next_char_is(&self, c: char) -> bool { ... } fn nth_char_is(&self, n: usize, c: char) -> bool { ... } fn next_2_are(&self, c1: char, c2: char) -> bool { ... } fn next_3_are(&self, c1: char, c2: char, c3: char) -> bool { ... } fn next_is_document_indicator(&self) -> bool { ... } fn next_is_document_start(&self) -> bool { ... } fn next_is_document_end(&self) -> bool { ... } fn skip_ws_to_eol( &mut self, skip_tabs: SkipTabs, ) -> (usize, Result<SkipTabs, &'static str>) { ... } fn next_can_be_plain_scalar(&self, in_flow: bool) -> bool { ... } fn next_is_blank_or_break(&self) -> bool { ... } fn next_is_blank_or_breakz(&self) -> bool { ... } fn next_is_blank(&self) -> bool { ... } fn next_is_break(&self) -> bool { ... } fn next_is_breakz(&self) -> bool { ... } fn next_is_z(&self) -> bool { ... } fn next_is_flow(&self) -> bool { ... } fn next_is_digit(&self) -> bool { ... } fn next_is_alpha(&self) -> bool { ... } fn skip_while_non_breakz(&mut self) -> usize { ... } fn skip_while_blank(&mut self) -> usize { ... } fn fetch_while_is_alpha(&mut self, out: &mut String) -> usize { ... }
}
Expand description

Interface for a source of characters.

Hiding the input’s implementation behind this trait allows mostly:

  • For input-specific optimizations (for instance, using str methods instead of manually transferring one char at a time to a buffer).
  • To return &strs referencing the input string, thus avoiding potentially costly allocations. Should users need an owned version of the data, they can always .to_owned() their YAML object.

Required Methods§

Source

fn lookahead(&mut self, count: usize)

A hint to the input source that we will need to read count characters.

If the input is exhausted, \0 can be used to pad the last characters and later returned. The characters must not be consumed, but may be placed in an internal buffer.

This method may be a no-op if buffering yields no performance improvement.

Implementers of Input must not load more than count characters into the buffer. The parser tracks how many characters are loaded in the buffer and acts accordingly.

Source

fn buflen(&self) -> usize

Return the number of buffered characters in self.

Source

fn bufmaxlen(&self) -> usize

Return the capacity of the buffer in self.

Source

fn raw_read_ch(&mut self) -> char

Read a character from the input stream and return it directly.

The internal buffer (if any) is bypassed.

Source

fn raw_read_non_breakz_ch(&mut self) -> Option<char>

Read a non-breakz a character from the input stream and return it directly.

The internal buffer (if any) is bypassed.

If the next character is a breakz, it is either not consumed or placed into the buffer (if any).

Source

fn skip(&mut self)

Consume the next character.

Source

fn skip_n(&mut self, count: usize)

Consume the next count character.

Source

fn peek(&self) -> char

Return the next character, without consuming it.

Users of the Input must make sure that the character has been loaded through a prior call to Input::lookahead. Implementors of Input may assume that a valid call to Input::lookahead has been made beforehand.

§Return

If the input source is not exhausted, returns the next character to be fed into the scanner. Otherwise, returns \0.

Source

fn peek_nth(&self, n: usize) -> char

Return the n-th character in the buffer, without consuming it.

This function assumes that the n-th character in the input has already been fetched through Input::lookahead.

Provided Methods§

Source

fn buf_is_empty(&self) -> bool

Return whether the buffer (!= stream) is empty.

Source

fn look_ch(&mut self) -> char

Look for the next character and return it.

The character is not consumed. Equivalent to calling Input::lookahead and Input::peek.

Source

fn next_char_is(&self, c: char) -> bool

Return whether the next character in the input source is equal to c.

This function assumes that the next character in the input has already been fetched through Input::lookahead.

Source

fn nth_char_is(&self, n: usize, c: char) -> bool

Return whether the n-th character in the input source is equal to c.

This function assumes that the n-th character in the input has already been fetched through Input::lookahead.

Source

fn next_2_are(&self, c1: char, c2: char) -> bool

Return whether the next 2 characters in the input source match the given characters.

This function assumes that the next 2 characters in the input have already been fetched through Input::lookahead.

Source

fn next_3_are(&self, c1: char, c2: char, c3: char) -> bool

Return whether the next 3 characters in the input source match the given characters.

This function assumes that the next 3 characters in the input have already been fetched through Input::lookahead.

Source

fn next_is_document_indicator(&self) -> bool

Check whether the next characters correspond to a document indicator.

This function assumes that the next 4 characters in the input has already been fetched through Input::lookahead.

Source

fn next_is_document_start(&self) -> bool

Check whether the next characters correspond to a start of document.

This function assumes that the next 4 characters in the input has already been fetched through Input::lookahead.

Source

fn next_is_document_end(&self) -> bool

Check whether the next characters correspond to an end of document.

This function assumes that the next 4 characters in the input has already been fetched through Input::lookahead.

Source

fn skip_ws_to_eol( &mut self, skip_tabs: SkipTabs, ) -> (usize, Result<SkipTabs, &'static str>)

Skip yaml whitespace at most up to eol. Also skips comments. Advances the input.

§Return

Return a tuple with the number of characters that were consumed and the result of skipping whitespace. The number of characters returned can be used to advance the index and column, since no end-of-line character will be consumed. See SkipTabs For more details on the success variant.

§Errors

Errors if a comment is encountered but it was not preceded by a whitespace. In that event, the first tuple element will contain the number of characters consumed prior to reaching the #.

Source

fn next_can_be_plain_scalar(&self, in_flow: bool) -> bool

Check whether the next characters may be part of a plain scalar.

This function assumes we are not given a blankz character.

Source

fn next_is_blank_or_break(&self) -> bool

Check whether the next character is a blank or a break.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a blank or a break, false otherwise.

Source

fn next_is_blank_or_breakz(&self) -> bool

Check whether the next character is a blank or a breakz.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a blank or [a break], false otherwise.

Source

fn next_is_blank(&self) -> bool

Check whether the next character is a blank.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a blank, false otherwise.

Source

fn next_is_break(&self) -> bool

Check whether the next character is a break.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a break, false otherwise.

Source

fn next_is_breakz(&self) -> bool

Check whether the next character is a breakz.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a breakz, false otherwise.

Source

fn next_is_z(&self) -> bool

Check whether the next character is a z.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a z, false otherwise.

Source

fn next_is_flow(&self) -> bool

Check whether the next character is a flow.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a flow, false otherwise.

Source

fn next_is_digit(&self) -> bool

Check whether the next character is a digit.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a digit, false otherwise.

Source

fn next_is_alpha(&self) -> bool

Check whether the next character is a letter.

The character must have previously been fetched through lookahead

§Return

Returns true if the character is a letter, false otherwise.

Source

fn skip_while_non_breakz(&mut self) -> usize

Skip characters from the input until a breakz is found.

The characters are consumed from the input.

§Return

Return the number of characters that were consumed. The number of characters returned can be used to advance the index and column, since no end-of-line character will be consumed.

Source

fn skip_while_blank(&mut self) -> usize

Skip characters from the input while blanks are found.

The characters are consumed from the input.

§Return

Return the number of characters that were consumed. The number of characters returned can be used to advance the index and column, since no end-of-line character will be consumed.

Source

fn fetch_while_is_alpha(&mut self, out: &mut String) -> usize

Fetch characters from the input while we encounter letters and store them in out.

The characters are consumed from the input.

§Return

Return the number of characters that were consumed. The number of characters returned can be used to advance the index and column, since no end-of-line character will be consumed.

Implementors§

Source§

impl<'a> Input for StrInput<'a>

Source§

impl<T: Iterator<Item = char>> Input for BufferedInput<T>