Skip to main content

CharsetEncoder

Struct CharsetEncoder 

Source
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,

Source

pub const DEFAULT_REPLACEMENT: char = '\u{fffd}'

Default replacement character used when unmappable input is replaced.

Source

pub const DEFAULT_FALLBACK_REPLACEMENT: char = '?'

Fallback replacement used when the default replacement is unmappable.

Source

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.

Source

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.
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 unmappable_action(&self) -> UnmappableAction

Returns the configured unmappable-character action.

§Returns

Returns the action used when target encoding cannot represent a character.

Source

pub fn set_unmappable_action(&mut self, action: UnmappableAction)

Sets the unmappable-character action.

§Parameters
  • action: New policy for unmappable input characters.
Source

pub const fn replacement(&self) -> char

Returns the configured replacement character.

§Returns

Returns the character encoded when UnmappableAction::Replace is used.

Source

pub fn set_replacement( &mut self, replacement: char, ) -> Result<(), CharsetEncodeError>

Sets the replacement character.

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

Returns Err when the codec cannot encode the given replacement.

Trait Implementations§

Source§

impl<C> Clone for CharsetEncoder<C>
where C: CharsetCodec + Clone, C::Unit: Clone,

Source§

fn clone(&self) -> CharsetEncoder<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<char, <C as CharsetCodec>::Unit> for CharsetEncoder<C>
where C: CharsetCodec,

Source§

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>

Encodes characters into the target charset while applying unmappable policy.

Source§

type Error = CharsetEncodeError

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 CharsetEncoder<C>
where C: CharsetCodec + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the encoder without exposing additional bounds for cached units.

Source§

impl<C> PartialEq for CharsetEncoder<C>

Source§

fn eq(&self, other: &Self) -> bool

Compares encoder configuration without leaking cached-unit trait bounds.

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 CharsetEncoder<C>
where C: CharsetCodec + Eq,

Auto Trait Implementations§

§

impl<C> Freeze for CharsetEncoder<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for CharsetEncoder<C>

§

impl<C> Send for CharsetEncoder<C>
where C: Send, <C as CharsetCodec>::Unit: Send,

§

impl<C> Sync for CharsetEncoder<C>
where C: Sync, <C as CharsetCodec>::Unit: Sync,

§

impl<C> Unpin for CharsetEncoder<C>
where C: Unpin, <C as CharsetCodec>::Unit: Unpin,

§

impl<C> UnsafeUnpin for CharsetEncoder<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for CharsetEncoder<C>

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.