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,
impl<C> CharsetDecoder<C>where
C: CharsetCodec,
Sourcepub const DEFAULT_REPLACEMENT: char = '\u{fffd}'
pub const DEFAULT_REPLACEMENT: char = '\u{fffd}'
Default replacement character used when malformed input is replaced.
Sourcepub const fn new(codec: C) -> Self
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.
Sourcepub fn with_replacement(self, replacement: char) -> Self
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.
Sourcepub fn codec_mut(&mut self) -> &mut C
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.
Sourcepub const fn malformed_action(&self) -> MalformedAction
pub const fn malformed_action(&self) -> MalformedAction
Returns the configured malformed-input action.
§Returns
Returns the action used when source input is malformed.
Sourcepub fn set_malformed_action(&mut self, action: MalformedAction)
pub fn set_malformed_action(&mut self, action: MalformedAction)
Sourcepub const fn replacement(&self) -> char
pub const fn replacement(&self) -> char
Returns the configured replacement character.
§Returns
Returns the character emitted when MalformedAction::Replace is used.
Sourcepub fn set_replacement(&mut self, replacement: char)
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,
impl<C> Clone for CharsetDecoder<C>where
C: CharsetCodec + Clone,
Source§fn clone(&self) -> CharsetDecoder<C>
fn clone(&self) -> CharsetDecoder<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C> Coder<<C as CharsetCodec>::Unit, char> for CharsetDecoder<C>where
C: CharsetCodec,
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>
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>
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
type Error = CharsetDecodeError
Source§impl<C> Debug for CharsetDecoder<C>where
C: CharsetCodec + Debug,
impl<C> Debug for CharsetDecoder<C>where
C: CharsetCodec + Debug,
Source§impl<C> PartialEq for CharsetDecoder<C>where
C: CharsetCodec + PartialEq,
impl<C> PartialEq for CharsetDecoder<C>where
C: CharsetCodec + PartialEq,
Source§fn eq(&self, other: &CharsetDecoder<C>) -> bool
fn eq(&self, other: &CharsetDecoder<C>) -> bool
self and other values to be equal, and is used by ==.