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>where
P: StreamTextParser,
impl<P> Utf8StreamParser<P>where
P: StreamTextParser,
pub fn new(inner: P) -> Self
Sourcepub fn push_bytes(
&mut self,
chunk: &[u8],
) -> Result<StreamTextChunk<P::Extracted>, Utf8StreamParserError>
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.
pub fn finish( &mut self, ) -> Result<StreamTextChunk<P::Extracted>, Utf8StreamParserError>
Sourcepub fn into_inner(self) -> Result<P, Utf8StreamParserError>
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.
Sourcepub fn into_inner_lossy(self) -> P
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.