Input

Trait Input 

Source
pub trait Input {
    type Lines: Iterator;
    type Line: AsRef<str>;
    type Bytes: Iterator<Item = u8>;

    // Required methods
    fn lines(self) -> Self::Lines;
    fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>;
    fn bytes(line: Self::Line) -> Self::Bytes;
}
Expand description

Types that can be passed to parsers as input.

The trait is implemented for &str, &[u8], BufReader, and &mut B for every type B that implements BufRead.

When parsing a file, you can take a BufReader<File> as input.

Required Associated Types§

Source

type Lines: Iterator

An iterator over lines of the input.

Source

type Line: AsRef<str>

A string or a reference to a string, which represents a line of the input.

Source

type Bytes: Iterator<Item = u8>

An iterator over bytes of a line.

Required Methods§

Source

fn lines(self) -> Self::Lines

Creates an iterator over lines from the input.

Source

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Converts a item in the lines iterator to a string.

Source

fn bytes(line: Self::Line) -> Self::Bytes

Creates an iterator over bytes from a line.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> Input for &'a str

Source§

type Lines = Lines<'a>

Source§

type Line = &'a str

Source§

type Bytes = Bytes<'a>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Source§

impl<'a> Input for &'a [u8]

Source§

type Lines = Lines<&'a [u8]>

Source§

type Line = String

Source§

type Bytes = IntoIter<u8>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Source§

impl<'a> Input for Lines<'a>

Source§

type Lines = Lines<'a>

Source§

type Line = &'a str

Source§

type Bytes = Bytes<'a>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Source§

impl<'a, B: BufRead> Input for &'a mut B

Source§

type Lines = Lines<&'a mut B>

Source§

type Line = String

Source§

type Bytes = IntoIter<u8>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Source§

impl<B: BufRead> Input for Lines<B>

Source§

type Lines = Lines<B>

Source§

type Line = String

Source§

type Bytes = IntoIter<u8>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Source§

impl<R: Read> Input for BufReader<R>

Source§

type Lines = Lines<BufReader<R>>

Source§

type Line = String

Source§

type Bytes = IntoIter<u8>

Source§

fn lines(self) -> Self::Lines

Source§

fn line(item: <Self::Lines as Iterator>::Item) -> Result<Self::Line, Error>

Source§

fn bytes(line: Self::Line) -> Self::Bytes

Implementors§