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,
impl<C> CharsetDecoder<C>where
C: CharsetCodec,
Sourcepub fn new(codec: C) -> Self
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.
Sourcepub fn with_policy(codec: C, policy: CharsetDecodePolicy) -> Self
pub fn with_policy(codec: C, policy: CharsetDecodePolicy) -> Self
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 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.
Trait Implementations§
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,
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>
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>
fn max_finish_output_len(&self) -> Result<usize, CapacityError>
Returns the maximum number of characters emitted by finishing internal state.
Source§fn transcode(
&mut self,
input: &[C::Unit],
input_index: usize,
output: &mut [char],
output_index: usize,
) -> Result<TranscodeProgress, Self::Error>
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>>
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
type Error = CharsetDecodeError
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> Debug for CharsetDecoder<C>where
C: CharsetCodec + Debug,
impl<C> Debug for CharsetDecoder<C>where
C: CharsetCodec + Debug,
impl<C> Eq for CharsetDecoder<C>where
C: CharsetCodec + Eq,
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 ==.