Struct CharacterStream

Source
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 an error will be returned.

Implementations§

Source§

impl<Reader: Read> CharacterStream<Reader>

Source

pub fn new(stream: Reader, is_lossy: bool) -> Self

Create a CharacterStream from a stream.

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

Source

pub fn lossy(self, is_lossy: bool) -> Self

Kinda builder pattern.

Source

pub fn peeky(self) -> PeekableCharacterStream<Reader, Peek>

Wrap self into a single-peek PeekableCharacterStream.

Source

pub fn peeky_multi(self) -> PeekableCharacterStream<Reader, MultiPeek>

Wrap self into a multi-peek PeekableCharacterStream.

Source

pub fn read_bytes(&mut self, amount: usize) -> Result<Vec<u8>, CharacterError>

Reads a set amount of bytes from the stream.

Set amount 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.

Source

pub fn read_byte(&mut self) -> Result<u8, CharacterError>

Reads a singluar byte from the stream.

Trait Implementations§

Source§

impl<Reader: Read> AsMut<Reader> for CharacterStream<Reader>

Source§

fn as_mut(&mut self) -> &mut Reader

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

impl<Reader: Read> AsRef<Reader> for CharacterStream<Reader>

Source§

fn as_ref(&self) -> &Reader

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

impl<Reader: Read> CharStream for CharacterStream<Reader>

Source§

fn read_char(&mut self) -> CharacterStreamResult

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.

Source§

fn is_lossy(&self) -> bool

Source§

impl<Reader: Debug + Read> Debug for CharacterStream<Reader>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Reader: Read> Deref for CharacterStream<Reader>

Source§

type Target = Reader

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<Reader: Read> DerefMut for CharacterStream<Reader>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<Reader: Read, PI> From<CharacterStream<Reader>> for PeekableCharacterStream<Reader, PI>

Source§

fn from(stream: CharacterStream<Reader>) -> Self

Converts to this type from the input type.
Source§

impl<Reader: Read> From<Reader> for CharacterStream<Reader>

Source§

fn from(reader: Reader) -> Self

Converts to this type from the input type.
Source§

impl<Reader: Read> IntoIterator for CharacterStream<Reader>

Source§

type Item = <<CharacterStream<Reader> as IntoIterator>::IntoIter as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = CharacterIterator<CharacterStream<Reader>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<Reader> Freeze for CharacterStream<Reader>
where Reader: Freeze,

§

impl<Reader> RefUnwindSafe for CharacterStream<Reader>
where Reader: RefUnwindSafe,

§

impl<Reader> Send for CharacterStream<Reader>
where Reader: Send,

§

impl<Reader> Sync for CharacterStream<Reader>
where Reader: Sync,

§

impl<Reader> Unpin for CharacterStream<Reader>
where Reader: Unpin,

§

impl<Reader> UnwindSafe for CharacterStream<Reader>
where Reader: 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.