Skip to main content

Utf8StreamParser

Struct Utf8StreamParser 

Source
pub struct Utf8StreamParser<P> { /* private fields */ }
Expand description

Wraps a StreamTextParser and accepts raw bytes, buffering partial UTF-8 code points.

This is useful when upstream data arrives as &[u8] and a code point may be split across chunk boundaries (for example 0xC3 followed by 0xA9 for é).

Implementations§

Source§

impl<P> Utf8StreamParser<P>

Source

pub fn new(inner: P) -> Self

Source

pub fn push_bytes( &mut self, chunk: &[u8], ) -> Result<StreamTextChunk<P::Extracted>, Utf8StreamParserError>

Feed a raw byte chunk.

If the chunk contains invalid UTF-8, this returns an error and rolls back the entire pushed chunk so callers can decide how to recover without the inner parser seeing a partial prefix from that chunk.

Source

pub fn finish( &mut self, ) -> Result<StreamTextChunk<P::Extracted>, Utf8StreamParserError>

Source

pub fn into_inner(self) -> Result<P, Utf8StreamParserError>

Return the wrapped parser if no undecoded UTF-8 bytes are buffered.

Use Self::finish first if you want to flush buffered text into the wrapped parser.

Source

pub fn into_inner_lossy(self) -> P

Return the wrapped parser without validating or flushing buffered undecoded bytes.

This may drop a partial UTF-8 code point that was buffered across chunk boundaries.

Trait Implementations§

Source§

impl<P: Debug> Debug for Utf8StreamParser<P>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<P> Freeze for Utf8StreamParser<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for Utf8StreamParser<P>
where P: RefUnwindSafe,

§

impl<P> Send for Utf8StreamParser<P>
where P: Send,

§

impl<P> Sync for Utf8StreamParser<P>
where P: Sync,

§

impl<P> Unpin for Utf8StreamParser<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for Utf8StreamParser<P>
where P: UnsafeUnpin,

§

impl<P> UnwindSafe for Utf8StreamParser<P>
where P: 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.