pub struct Utf32ByteCodec { /* private fields */ }Expand description
Combined byte-serialized UTF-32 codec.
The codec uses one configured byte order for both decoding and encoding. It
does not detect, consume, or emit a BOM automatically; callers should use
crate::UnicodeBom when a byte stream may carry an explicit BOM.
§Examples
use qubit_codec_text::{
ByteOrder,
CharsetCodec,
CharsetEncodeProbe,
Codec,
Charset,
Utf32,
Utf32ByteCodec,
};
let codec = Utf32ByteCodec::new(ByteOrder::BigEndian);
assert_eq!(Charset::UTF_32BE, codec.charset());
assert_eq!(Utf32::MAX_BYTES_PER_CHAR, codec.max_units_per_value().get());
let mut output = [0_u8; Utf32::MAX_BYTES_PER_CHAR];
let written = codec.encode_len('中', 0).expect("mappable");
unsafe {
codec.encode_unchecked(&'中', &mut output, 0).expect("buffer fits");
}
let (value, consumed) = unsafe {
codec.decode_unchecked(&output[..written], 0).expect("valid UTF-32BE")
};
assert_eq!(('中', written), (value, consumed.get()));Implementations§
Source§impl Utf32ByteCodec
impl Utf32ByteCodec
Sourcepub const fn byte_order(self) -> ByteOrder
pub const fn byte_order(self) -> ByteOrder
Sourcepub const fn charset(self) -> Charset
pub const fn charset(self) -> Charset
Returns the fixed-endian UTF-32 charset descriptor.
§Returns
Returns Charset::UTF_32LE or Charset::UTF_32BE according to this
codec’s configured byte order.
Trait Implementations§
Source§impl CharsetCodec for Utf32ByteCodec
impl CharsetCodec for Utf32ByteCodec
Source§fn charset(&self) -> Charset
fn charset(&self) -> Charset
Returns the fixed-endian UTF-32 charset for the configured byte order.
§Returns
Returns Charset::UTF_32BE when configured with
ByteOrder::BigEndian, otherwise Charset::UTF_32LE.
Source§impl CharsetEncodeProbe for Utf32ByteCodec
impl CharsetEncodeProbe for Utf32ByteCodec
Source§fn encode_len(&self, _ch: char, _index: usize) -> CharsetEncodeResult<usize>
fn encode_len(&self, _ch: char, _index: usize) -> CharsetEncodeResult<usize>
Source§impl Clone for Utf32ByteCodec
impl Clone for Utf32ByteCodec
Source§fn clone(&self) -> Utf32ByteCodec
fn clone(&self) -> Utf32ByteCodec
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Codec for Utf32ByteCodec
impl Codec for Utf32ByteCodec
Source§type DecodeError = CharsetDecodeError
type DecodeError = CharsetDecodeError
Error reported when decoding malformed units.
Source§type EncodeError = CharsetEncodeError
type EncodeError = CharsetEncodeError
Error reported when encoding an unsupported value.
Source§fn min_units_per_value(&self) -> NonZeroUsize
fn min_units_per_value(&self) -> NonZeroUsize
Returns the minimum possible unit count for one encoded value. Read more
Source§fn max_units_per_value(&self) -> NonZeroUsize
fn max_units_per_value(&self) -> NonZeroUsize
Returns the maximum non-zero unit count needed to encode or decode one value. Read more
Source§unsafe fn decode_unchecked(
&self,
input: &[u8],
index: usize,
) -> CharsetDecodeResult<(char, NonZeroUsize)>
unsafe fn decode_unchecked( &self, input: &[u8], index: usize, ) -> CharsetDecodeResult<(char, NonZeroUsize)>
Source§unsafe fn encode_unchecked(
&self,
ch: &char,
output: &mut [u8],
index: usize,
) -> CharsetEncodeResult<usize>
unsafe fn encode_unchecked( &self, ch: &char, output: &mut [u8], index: usize, ) -> CharsetEncodeResult<usize>
impl Copy for Utf32ByteCodec
Source§impl Debug for Utf32ByteCodec
impl Debug for Utf32ByteCodec
impl Eq for Utf32ByteCodec
Source§impl PartialEq for Utf32ByteCodec
impl PartialEq for Utf32ByteCodec
Source§fn eq(&self, other: &Utf32ByteCodec) -> bool
fn eq(&self, other: &Utf32ByteCodec) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Utf32ByteCodec
Auto Trait Implementations§
impl Freeze for Utf32ByteCodec
impl RefUnwindSafe for Utf32ByteCodec
impl Send for Utf32ByteCodec
impl Sync for Utf32ByteCodec
impl Unpin for Utf32ByteCodec
impl UnsafeUnpin for Utf32ByteCodec
impl UnwindSafe for Utf32ByteCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more