pub struct Utf16ByteCodec { /* private fields */ }Expand description
Combined byte-serialized UTF-16 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,
Utf16,
Utf16ByteCodec,
};
let codec = Utf16ByteCodec::new(ByteOrder::LittleEndian);
assert_eq!(Charset::UTF_16LE, codec.charset());
assert_eq!(Utf16::MAX_BYTES_PER_CHAR, codec.max_units_per_value().get());
let mut output = [0_u8; Utf16::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-16LE")
};
assert_eq!(('😀', written), (value, consumed.get()));Implementations§
Source§impl Utf16ByteCodec
impl Utf16ByteCodec
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-16 charset descriptor.
§Returns
Returns Charset::UTF_16LE or Charset::UTF_16BE according to this
codec’s configured byte order.
Trait Implementations§
Source§impl CharsetCodec for Utf16ByteCodec
impl CharsetCodec for Utf16ByteCodec
Source§fn charset(&self) -> Charset
fn charset(&self) -> Charset
Returns the fixed-endian UTF-16 charset for the configured byte order.
§Returns
Returns Charset::UTF_16BE when configured with
ByteOrder::BigEndian, otherwise Charset::UTF_16LE.
Source§impl CharsetEncodeProbe for Utf16ByteCodec
impl CharsetEncodeProbe for Utf16ByteCodec
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 Utf16ByteCodec
impl Clone for Utf16ByteCodec
Source§fn clone(&self) -> Utf16ByteCodec
fn clone(&self) -> Utf16ByteCodec
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 Utf16ByteCodec
impl Codec for Utf16ByteCodec
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 Utf16ByteCodec
Source§impl Debug for Utf16ByteCodec
impl Debug for Utf16ByteCodec
impl Eq for Utf16ByteCodec
Source§impl PartialEq for Utf16ByteCodec
impl PartialEq for Utf16ByteCodec
Source§fn eq(&self, other: &Utf16ByteCodec) -> bool
fn eq(&self, other: &Utf16ByteCodec) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Utf16ByteCodec
Auto Trait Implementations§
impl Freeze for Utf16ByteCodec
impl RefUnwindSafe for Utf16ByteCodec
impl Send for Utf16ByteCodec
impl Sync for Utf16ByteCodec
impl Unpin for Utf16ByteCodec
impl UnsafeUnpin for Utf16ByteCodec
impl UnwindSafe for Utf16ByteCodec
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