Struct LossyDecoder
pub struct LossyDecoder<F>{ /* private fields */ }
Expand description
A push-based, lossy decoder for UTF-8. Errors are replaced with the U+FFFD replacement character.
Users “push” bytes into the decoder, which in turn “pushes” &str
slices into a callback.
For example, String::from_utf8_lossy
(but returning String
instead of Cow
)
can be rewritten as:
fn string_from_utf8_lossy(input: &[u8]) -> String {
let mut string = String::new();
rama_utils::str::utf8::LossyDecoder::new(|s| string.push_str(s)).feed(input);
string
}
Note: Dropping the decoder signals the end of the input:
If the last input chunk ended with an incomplete byte sequence for a code point,
this is an error and a replacement character is emitted.
Use std::mem::forget
to inhibit this behavior.
Implementations§
§impl<F> LossyDecoder<F>
impl<F> LossyDecoder<F>
pub fn new(push_str: F) -> LossyDecoder<F>
pub fn new(push_str: F) -> LossyDecoder<F>
Create a new decoder from a callback.
pub fn feed(&mut self, input: &[u8])
pub fn feed(&mut self, input: &[u8])
Feed one chunk of input into the decoder.
The input is decoded lossily
and the callback called once or more with &str
string slices.
If the UTF-8 byte sequence for one code point was split into this bytes chunk and previous bytes chunks, it will be correctly pieced back together.
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for LossyDecoder<F>where
F: Freeze,
impl<F> RefUnwindSafe for LossyDecoder<F>where
F: RefUnwindSafe,
impl<F> Send for LossyDecoder<F>where
F: Send,
impl<F> Sync for LossyDecoder<F>where
F: Sync,
impl<F> Unpin for LossyDecoder<F>where
F: Unpin,
impl<F> UnwindSafe for LossyDecoder<F>where
F: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more