Skip to main content

CharsetStringDecoder

Struct CharsetStringDecoder 

Source
pub struct CharsetStringDecoder<C>
where C: CharsetCodec,
{ /* private fields */ }
Expand description

Convenience decoder for complete inputs that should become a String.

CharsetStringDecoder owns a CharsetDecoder and adapts the char output expected by the transcode layer into UTF-8 String storage. Lower-level streaming code should use CharsetDecoder directly; this type is for closed, in-memory string conversions.

§Type Parameters

  • C: Charset codec used to decode source units into Unicode scalar values.

§Examples

use qubit_codec_text::Utf8Codec;
use qubit_io_text::CharsetStringDecoder;

let mut decoder = CharsetStringDecoder::new(Utf8Codec);
let decoded = decoder.decode_to_string("中文".as_bytes())?;
assert_eq!("中文", decoded);

Implementations§

Source§

impl<C> CharsetStringDecoder<C>
where C: CharsetCodec,

Source

pub fn new(codec: C) -> Self

Creates a string decoder with the default replacement policy.

§Parameters
  • codec: Charset codec used to decode input units.
§Returns

Returns a decoder using MalformedAction::Replace.

Source

pub fn with_policy(codec: C, policy: CharsetDecodePolicy) -> Self

Creates a string decoder with an explicit malformed-input policy.

§Parameters
  • codec: Charset codec used to decode input units.
  • policy: Malformed-input policy used by the decoder.
§Returns

Returns a string decoder configured with policy.

Source

pub const fn malformed_action(&self) -> MalformedAction

Returns the configured malformed-input action.

§Returns

The action used for malformed or incomplete input.

Source

pub const fn replacement(&self) -> char

Returns the configured replacement character.

§Returns

The character emitted when the configured action replaces input.

Source

pub const fn decoder(&self) -> &CharsetDecoder<C>

Returns the wrapped charset decoder.

§Returns

A shared reference to the decoder owned by this adapter.

Source

pub fn decoder_mut(&mut self) -> &mut CharsetDecoder<C>

Returns a mutable reference to the wrapped charset decoder.

§Returns

A mutable reference to the decoder owned by this adapter.

Source

pub fn into_decoder(self) -> CharsetDecoder<C>

Consumes this string decoder and returns the wrapped charset decoder.

§Returns

The decoder previously owned by this adapter.

Source

pub fn decode_to_string( &mut self, input: &[C::Unit], ) -> Result<String, CharsetDecodeError>

Decodes a complete input slice into an owned String.

§Parameters
  • input: Complete source units.
§Returns

Returns decoded UTF-8 text.

§Errors

Returns CharsetDecodeError when decoding fails, output sizing overflows, or the configured decode policy rejects malformed or incomplete input.

Source

pub fn decode_to_string_into( &mut self, input: &[C::Unit], input_index: usize, output: &mut String, ) -> Result<(), CharsetDecodeError>

Decodes a complete input slice and appends the decoded text to output.

This method treats input[input_index..] as a closed stream. If the underlying decoder requests more input, the tail is reported as CharsetDecodeErrorKind::IncompleteSequence.

On success, decoded text is appended to output. If this method returns Err, the destination string retains its original contents. This guarantee applies to the destination only; it does not roll back decoder state or cover panics. Streaming text-reader operations have their own prefix-retention contracts.

§Parameters
  • input: Complete input slice visible to the decoder.
  • input_index: Absolute index where decoding starts.
  • output: String receiving decoded text.
§Returns

Returns () after appending all decoded text successfully.

§Errors

Returns CharsetDecodeError when input_index is outside input, decoding fails, or output sizing overflows.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.