Skip to main content

CharsetDecoder

Struct CharsetDecoder 

Source
pub struct CharsetDecoder<C>
where C: CharsetCodec,
{ /* private fields */ }
Expand description

Converts units of one charset into Unicode scalar values.

CharsetDecoder wraps a low-level CharsetCodec and applies the configured MalformedAction whenever the codec reports malformed input. The decoder asks the wrapped codec whether one value can be decoded from the currently available units. If the codec reports a valid incomplete prefix, the tail is left in the caller-provided input slice and crate::TranscodeStatus::NeedInput is returned. Callers must handle incomplete EOF tails before calling BufferedTranscoder::finish.

§Type Parameters

  • C: Low-level charset codec used to decode source storage units into one Unicode scalar value.

Implementations§

Source§

impl<C> CharsetDecoder<C>
where C: CharsetCodec,

Source

pub fn new(codec: C) -> Self

Creates a decoder with default replacement policy.

§Parameters
  • codec: Low-level charset codec used to decode input units.
§Returns

Returns a decoder whose malformed action is MalformedAction::Replace and whose replacement character is U+FFFD.

Source

pub fn with_policy(codec: C, policy: CharsetDecodePolicy) -> Self

Creates a decoder with an explicit malformed-input policy.

§Parameters
  • codec: Low-level charset codec used to decode input units.
  • policy: Malformed-input policy used by the decoder.
§Returns

Returns a decoder configured with policy.

Source

pub const fn malformed_action(&self) -> MalformedAction

Returns the configured malformed-input action.

§Returns

Returns the action used when source input is malformed.

Source

pub const fn replacement(&self) -> char

Returns the configured replacement character.

§Returns

Returns the character emitted when MalformedAction::Replace is used.

Trait Implementations§

Source§

impl<C> BufferedDecoder<<C as Codec>::Unit, char> for CharsetDecoder<C>
where C: CharsetCodec,

Source§

impl<C> BufferedTranscoder<<C as Codec>::Unit, char> for CharsetDecoder<C>
where C: CharsetCodec,

Source§

fn max_output_len(&self, input_len: usize) -> Result<usize, CapacityError>

Returns the maximum number of characters decoded from input_len units.

Source§

fn max_finish_output_len(&self) -> Result<usize, CapacityError>

Returns the maximum number of characters emitted by finishing internal state.

Source§

fn reset(&mut self)

Clears hook-owned state while keeping decoder policy.

Source§

fn transcode( &mut self, input: &[C::Unit], input_index: usize, output: &mut [char], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>

Decodes source units into Unicode scalar values while applying malformed policy.

Source§

fn finish( &mut self, output: &mut [char], output_index: usize, ) -> Result<usize, FinishError<Self::Error>>

Finishes decoder-owned final output after EOF.

Source§

type Error = CharsetDecodeError

Error reported for semantic conversion failures.
Source§

impl<C> Clone for CharsetDecoder<C>
where C: CharsetCodec + Clone,

Source§

fn clone(&self) -> CharsetDecoder<C>

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<C> Debug for CharsetDecoder<C>
where C: CharsetCodec + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C> Eq for CharsetDecoder<C>
where C: CharsetCodec + Eq,

Source§

impl<C> PartialEq for CharsetDecoder<C>

Source§

fn eq(&self, other: &CharsetDecoder<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C> StructuralPartialEq for CharsetDecoder<C>
where C: CharsetCodec,

Auto Trait Implementations§

§

impl<C> Freeze for CharsetDecoder<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for CharsetDecoder<C>
where C: RefUnwindSafe,

§

impl<C> Send for CharsetDecoder<C>
where C: Send,

§

impl<C> Sync for CharsetDecoder<C>
where C: Sync,

§

impl<C> Unpin for CharsetDecoder<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for CharsetDecoder<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for CharsetDecoder<C>
where C: 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> 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 = 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.