Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder { /* private fields */ }
Expand description

A decoder for input in pieces: decode(piece, last, out) appends the text of each piece to out; a sequence cut between two pieces is finished by the next one. The output is the same as decoding the whole input at once with decode_label (without its byte-order mark rule; see Decoder::sniffing). Shift_JIS’s “あ” in two pieces, 0x82 and then 0xA0 with last, gives “あ”.

Implementations§

Source§

impl Decoder

Source

pub fn new(label: Label) -> Decoder

A decoder of the encoding a label names (encoding::label).

Source

pub fn sniffing(label: Label) -> Decoder

A decoder with the standard’s byte-order mark rule (its “decode”): a UTF-8, UTF-16LE or UTF-16BE byte-order mark at the start wins over the label and is dropped.

Source

pub fn label(&self) -> Label

The encoding decoded: the label’s, or the byte-order mark’s once one was found.

Source

pub fn malformed(&self) -> bool

Whether some input was malformed (a U+FFFD in the output came from an error, not from the input).

Source

pub fn decode(&mut self, input: &[u8], last: bool, out: &mut String)

Append the text of input to out. last: no more input follows; an open sequence becomes U+FFFD, and a following call starts a new input in the encoding label names (a byte-order mark is not looked for again). The output grows by at most three bytes per input byte, and by six for what an earlier piece left open.

Trait Implementations§

Source§

impl Clone for Decoder

Source§

fn clone(&self) -> Decoder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Decoder

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.