pub struct CharsetEncoder<C>where
C: CharsetCodec,{ /* private fields */ }Expand description
Converts Unicode scalar values into units of one charset.
CharsetEncoder wraps a low-level 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: CharsetCodec,
impl<C> CharsetEncoder<C>where
C: CharsetCodec,
Sourcepub const DEFAULT_REPLACEMENT: char = '\u{fffd}'
pub const DEFAULT_REPLACEMENT: char = '\u{fffd}'
Default replacement character used when unmappable input is replaced.
Sourcepub const DEFAULT_FALLBACK_REPLACEMENT: char = '?'
pub const DEFAULT_FALLBACK_REPLACEMENT: char = '?'
Fallback replacement used when the default replacement is unmappable.
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
CharsetEncoder::DEFAULT_REPLACEMENT. If the default cannot be encoded
by the codec, CharsetEncoder::DEFAULT_FALLBACK_REPLACEMENT is used.
Sourcepub fn with_replacement(
self,
replacement: char,
) -> Result<Self, CharsetEncodeError>
pub fn with_replacement( self, replacement: char, ) -> Result<Self, CharsetEncodeError>
Creates an encoder with the provided replacement character.
The replacement character is checked once on construction. If the codec cannot encode it, this returns an error immediately.
§Parameters
replacement: Replacement character for unmappable input.
§Returns
Ok(Self)when the character is encodable by the codec.Err(Self::Error)when the replacement is unsupported.
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 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 fn set_unmappable_action(&mut self, action: UnmappableAction)
pub fn set_unmappable_action(&mut self, action: UnmappableAction)
Sets the unmappable-character action.
§Parameters
action: New policy for unmappable input characters.
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.
Sourcepub fn set_replacement(
&mut self,
replacement: char,
) -> Result<(), CharsetEncodeError>
pub fn set_replacement( &mut self, replacement: char, ) -> Result<(), CharsetEncodeError>
Trait Implementations§
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 moreSource§impl<C> Coder<char, <C as CharsetCodec>::Unit> for CharsetEncoder<C>where
C: CharsetCodec,
impl<C> Coder<char, <C as CharsetCodec>::Unit> for CharsetEncoder<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 target units needed for input_len characters.
Source§fn convert(
&mut self,
input: &[char],
input_index: usize,
output: &mut [C::Unit],
output_index: usize,
) -> Result<CoderProgress, Self::Error>
fn convert( &mut self, input: &[char], input_index: usize, output: &mut [C::Unit], output_index: usize, ) -> Result<CoderProgress, Self::Error>
Encodes characters into the target charset while applying unmappable policy.