Struct tendril::stream::LossyDecoder

source ·
pub struct LossyDecoder<Sink, A = NonAtomic>
where Sink: TendrilSink<UTF8, A>, A: Atomicity,
{ inner: LossyDecoderInner<Sink, A>, }
Expand description

A TendrilSink adaptor that takes bytes, decodes them as the given character encoding, lossily replace ill-formed byte sequences with U+FFFD replacement characters, and emits Unicode (StrTendril).

This allocates new tendrils for encodings other than UTF-8.

Fields§

§inner: LossyDecoderInner<Sink, A>

Implementations§

source§

impl<Sink, A> LossyDecoder<Sink, A>
where Sink: TendrilSink<UTF8, A>, A: Atomicity,

source

pub fn new_encoding_rs(encoding: &'static Encoding, sink: Sink) -> Self

Create a new incremental decoder using the encoding_rs crate.

source

pub fn utf8(sink: Sink) -> LossyDecoder<Sink, A>

Create a new incremental decoder for the UTF-8 encoding.

This is useful for content that is known at run-time to be UTF-8 (whereas Utf8LossyDecoder requires knowning at compile-time.)

source

pub fn inner_sink(&self) -> &Sink

Give a reference to the inner sink.

source

pub fn inner_sink_mut(&mut self) -> &mut Sink

Give a mutable reference to the inner sink.

Trait Implementations§

source§

impl<Sink, A> TendrilSink<Bytes, A> for LossyDecoder<Sink, A>
where Sink: TendrilSink<UTF8, A>, A: Atomicity,

source§

fn process(&mut self, t: Tendril<Bytes, A>)

Process this tendril.
source§

fn error(&mut self, desc: Cow<'static, str>)

Indicates that an error has occurred.
source§

type Output = <Sink as TendrilSink<UTF8, A>>::Output

What the overall result of processing is.
source§

fn finish(self) -> Sink::Output

Indicates the end of the stream.
source§

fn one<T>(self, t: T) -> Self::Output
where Self: Sized, T: Into<Tendril<F, A>>,

Process one tendril and finish.
source§

fn from_iter<I>(self, i: I) -> Self::Output
where Self: Sized, I: IntoIterator, I::Item: Into<Tendril<F, A>>,

Consume an iterator of tendrils, processing each item, then finish.
source§

fn read_from<R>(self, r: &mut R) -> Result<Self::Output>
where Self: Sized, R: Read, F: SliceFormat<Slice = [u8]>,

Read from the given stream of bytes until exhaustion and process incrementally, then finish. Return Err at the first I/O error.
source§

fn from_file<P>(self, path: P) -> Result<Self::Output>
where Self: Sized, P: AsRef<Path>, F: SliceFormat<Slice = [u8]>,

Read from the file at the given path and process incrementally, then finish. Return Err at the first I/O error.

Auto Trait Implementations§

§

impl<Sink, A> Freeze for LossyDecoder<Sink, A>
where Sink: Freeze,

§

impl<Sink, A> RefUnwindSafe for LossyDecoder<Sink, A>
where Sink: RefUnwindSafe, A: RefUnwindSafe,

§

impl<Sink, A> Send for LossyDecoder<Sink, A>
where Sink: Send, A: Send,

§

impl<Sink, A> Sync for LossyDecoder<Sink, A>
where Sink: Sync, A: Sync,

§

impl<Sink, A> Unpin for LossyDecoder<Sink, A>
where Sink: Unpin, A: Unpin,

§

impl<Sink, A> UnwindSafe for LossyDecoder<Sink, A>
where Sink: UnwindSafe, A: 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.