pub struct CharsetEncoder<C>where
C: CharsetEncodeProbe,{ /* private fields */ }Expand description
Converts Unicode scalar values into units of one charset.
CharsetEncoder wraps a low-level crate::CharsetCodec and applies the
configured UnmappableAction whenever the codec reports that an input
character cannot be represented by the target charset.
§Type Parameters
C: Low-level charset codec used to encode one character into target storage units.
Implementations§
Source§impl<C> CharsetEncoder<C>where
C: CharsetEncodeProbe,
impl<C> CharsetEncoder<C>where
C: CharsetEncodeProbe,
Sourcepub fn new(codec: C) -> Self
pub fn new(codec: C) -> Self
Creates an encoder with default replacement policy.
§Parameters
codec: Low-level charset codec used to encode output units.
§Returns
Returns an encoder whose unmappable action is
UnmappableAction::Replace and whose replacement character is
CharsetEncodePolicy::DEFAULT_REPLACEMENT. If the default cannot be
encoded by the codec,
CharsetEncodePolicy::DEFAULT_FALLBACK_REPLACEMENT is used.
§Panics
Panics when neither CharsetEncodePolicy::DEFAULT_REPLACEMENT nor
CharsetEncodePolicy::DEFAULT_FALLBACK_REPLACEMENT can be encoded by
codec.
Built-in codecs can always encode the fallback ?; failure here means
the supplied codec cannot encode a minimal ASCII replacement. For custom
crate::CharsetCodec implementations, this indicates a broken codec
invariant rather than recoverable input data.
Sourcepub fn with_policy(
codec: C,
policy: CharsetEncodePolicy,
) -> Result<Self, CharsetEncodeError>
pub fn with_policy( codec: C, policy: CharsetEncodePolicy, ) -> Result<Self, CharsetEncodeError>
Creates an encoder with an explicit unmappable-input policy.
§Errors
Returns an error when policy uses replacement and the replacement
character cannot be encoded by codec.
Sourcepub const fn unmappable_action(&self) -> UnmappableAction
pub const fn unmappable_action(&self) -> UnmappableAction
Returns the configured unmappable-character action.
§Returns
Returns the action used when target encoding cannot represent a character.
Sourcepub const fn replacement(&self) -> char
pub const fn replacement(&self) -> char
Returns the configured replacement character.
§Returns
Returns the character encoded when UnmappableAction::Replace is
used.
Trait Implementations§
impl<C> BufferedEncoder<char, <C as Codec>::Unit> for CharsetEncoder<C>where
C: CharsetEncodeProbe,
Source§impl<C> BufferedTranscoder<char, <C as Codec>::Unit> for CharsetEncoder<C>where
C: CharsetEncodeProbe,
impl<C> BufferedTranscoder<char, <C as Codec>::Unit> for CharsetEncoder<C>where
C: CharsetEncodeProbe,
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 target units needed for input_len
characters.
Source§fn max_finish_output_len(&self) -> Result<usize, CapacityError>
fn max_finish_output_len(&self) -> Result<usize, CapacityError>
Returns the maximum target units emitted by finishing internal state.
Source§fn transcode(
&mut self,
input: &[char],
input_index: usize,
output: &mut [C::Unit],
output_index: usize,
) -> Result<TranscodeProgress, Self::Error>
fn transcode( &mut self, input: &[char], input_index: usize, output: &mut [C::Unit], output_index: usize, ) -> Result<TranscodeProgress, Self::Error>
Encodes characters into the target charset while applying unmappable policy.
Source§fn finish(
&mut self,
output: &mut [C::Unit],
output_index: usize,
) -> Result<usize, FinishError<Self::Error>>
fn finish( &mut self, output: &mut [C::Unit], output_index: usize, ) -> Result<usize, FinishError<Self::Error>>
Finishes encoder-owned final output after EOF.
Source§type Error = CharsetEncodeError
type Error = CharsetEncodeError
Source§impl<C> Clone for CharsetEncoder<C>
impl<C> Clone for CharsetEncoder<C>
Source§fn clone(&self) -> CharsetEncoder<C>
fn clone(&self) -> CharsetEncoder<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more