pub struct Utf32U32Codec;Expand description
Combined UTF-32 u32 code-unit codec.
Utf32U32Codec works with raw UTF-32 scalar-value units rather than
serialized bytes. Use crate::Utf32ByteCodec for byte streams with an
explicit byte order.
§Examples
use qubit_codec_text::{
CharsetCodec,
CharsetEncodeProbe,
Codec,
Charset,
Utf32,
Utf32U32Codec,
};
let codec = Utf32U32Codec;
assert_eq!(Charset::UTF_32, codec.charset());
assert_eq!(Utf32::MAX_UNITS_PER_CHAR, codec.max_units_per_value().get());
let mut output = [0_u32; Utf32::MAX_UNITS_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-32")
};
assert_eq!(('中', written), (value, consumed.get()));Implementations§
Trait Implementations§
Source§impl CharsetCodec for Utf32U32Codec
impl CharsetCodec for Utf32U32Codec
Source§impl CharsetEncodeProbe for Utf32U32Codec
impl CharsetEncodeProbe for Utf32U32Codec
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 Utf32U32Codec
impl Clone for Utf32U32Codec
Source§fn clone(&self) -> Utf32U32Codec
fn clone(&self) -> Utf32U32Codec
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 Utf32U32Codec
impl Codec for Utf32U32Codec
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: &[u32],
index: usize,
) -> CharsetDecodeResult<(char, NonZeroUsize)>
unsafe fn decode_unchecked( &self, input: &[u32], index: usize, ) -> CharsetDecodeResult<(char, NonZeroUsize)>
Source§unsafe fn encode_unchecked(
&self,
ch: &char,
output: &mut [u32],
index: usize,
) -> CharsetEncodeResult<usize>
unsafe fn encode_unchecked( &self, ch: &char, output: &mut [u32], index: usize, ) -> CharsetEncodeResult<usize>
impl Copy for Utf32U32Codec
Source§impl Debug for Utf32U32Codec
impl Debug for Utf32U32Codec
Source§impl Default for Utf32U32Codec
impl Default for Utf32U32Codec
Source§fn default() -> Utf32U32Codec
fn default() -> Utf32U32Codec
Returns the “default value” for a type. Read more
impl Eq for Utf32U32Codec
Source§impl Hash for Utf32U32Codec
impl Hash for Utf32U32Codec
Source§impl PartialEq for Utf32U32Codec
impl PartialEq for Utf32U32Codec
Source§fn eq(&self, other: &Utf32U32Codec) -> bool
fn eq(&self, other: &Utf32U32Codec) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Utf32U32Codec
Auto Trait Implementations§
impl Freeze for Utf32U32Codec
impl RefUnwindSafe for Utf32U32Codec
impl Send for Utf32U32Codec
impl Sync for Utf32U32Codec
impl Unpin for Utf32U32Codec
impl UnsafeUnpin for Utf32U32Codec
impl UnwindSafe for Utf32U32Codec
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