pub struct CharacterStream<Reader: Read> {
    pub stream: Reader,
    pub is_lossy: bool,
}
Expand description

Wrapper struct for any stream that implements BufRead and Seek.

It allows you to read in bytes from a stream, and attempt to parse them into characters.

These bytes however, must be valid UTF-8 code points.

This wrapper does NOT parse graphemes.

Fields

stream: Reader

The stream from which the incoming bytes are from.

is_lossy: bool

Whether or not we should care whether invalid bytes are detected.

If true, then invalid byte sequences will be replaced with a U+FFFD.

If false, then Failure will be the returned result.

Implementations

Create a CharacterStream from a stream.

The created CharacterStream will not be lossy.

Create a CharacterStream from a stream.

Set is_lossy to true if you don’t want to handle invalid byte sequences.

Reads a set amount of bytes from the stream.

Set up_to to the amount of bytes you would like to read.

Upon success, a Vec<u8> is returned, holding the read bytes.

Upon failure, an error is returned.

Does exactly what read_bytes performs, the difference being it seeks back to the position before the read, serving as a lookahead function.

Reads a singluar byte from the stream.

Does exactly what read_byte performs, the difference being it seeks back to the position before the read, serving as a lookahead function.

Attempts to read a character from the stream.

If is_lossy is set to true, then invalid byte sequences will be a U+FFFD.

If is_lossy is set to false, then invalid byte sequences will be returned in addition to a parse error.

Performs the same action as read_char, the difference being, it seeks back to the position prior to the read.

Trait Implementations

Converts this type into a mutable reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.