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.

§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 const DEFAULT_REPLACEMENT: char = '\u{fffd}'

Default replacement character used when malformed input is replaced.

Source

pub const 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_replacement(self, replacement: char) -> Self

Creates a decoder with a custom replacement character.

This method performs no codec-level validation because malformed-input replacement for decoding writes directly to the output char buffer.

§Parameters
  • replacement: Replacement character for malformed sequences.
§Returns

Returns a new decoder configured with the provided replacement.

Source

pub const fn codec(&self) -> &C

Returns the wrapped low-level codec.

§Returns

Returns a shared reference to the configured codec.

Source

pub fn codec_mut(&mut self) -> &mut C

Returns a mutable reference to the wrapped codec.

§Returns

Returns a mutable reference to the configured codec.

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 fn set_malformed_action(&mut self, action: MalformedAction)

Sets the malformed-input action.

§Parameters
  • action: New policy for malformed input units.
Source

pub const fn replacement(&self) -> char

Returns the configured replacement character.

§Returns

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

Source

pub fn set_replacement(&mut self, replacement: char)

Sets the replacement character.

§Parameters
  • replacement: New replacement character used by replace policy.

Trait Implementations§

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> Coder<<C as CharsetCodec>::Unit, char> for CharsetDecoder<C>
where C: CharsetCodec,

Source§

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

Returns the maximum number of characters decoded from input_len units.

Source§

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

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

Source§

type Error = CharsetDecodeError

Error reported for semantic conversion failures.
Source§

fn reset(&mut self)

Resets state retained between conversion calls. Read more
Source§

fn finish( &mut self, _output: &mut [Output], _output_index: usize, ) -> Result<CoderProgress, Self::Error>

Flushes any buffered output after input conversion is complete. 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> 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> Eq for CharsetDecoder<C>
where C: CharsetCodec + Eq,

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.