Skip to main content

CharsetEncoder

Struct CharsetEncoder 

Source
pub struct CharsetEncoder<C>{ /* 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>

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 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.

Source

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.

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 const fn replacement(&self) -> char

Returns the configured replacement character.

§Returns

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

Trait Implementations§

Source§

impl<C> BufferedEncoder<char, <C as Codec>::Unit> for CharsetEncoder<C>

Source§

impl<C> BufferedTranscoder<char, <C as Codec>::Unit> for CharsetEncoder<C>

Source§

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>

Returns the maximum target units emitted by finishing internal state.

Source§

fn reset(&mut self)

Clears hook-owned state while keeping encoder policy.

Source§

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

Finishes encoder-owned final output after EOF.

Source§

type Error = CharsetEncodeError

Error reported for semantic conversion failures.
Source§

impl<C> Clone for CharsetEncoder<C>

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> Debug for CharsetEncoder<C>

Source§

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

Formats the encoder without exposing additional bounds for unit values.

Source§

impl<C> Eq for CharsetEncoder<C>

Source§

impl<C> PartialEq for CharsetEncoder<C>

Source§

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

Compares encoder configuration without leaking 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.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

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.