pub struct Utf8Codec;Expand description
UTF-8 byte-buffer charset codec.
§Examples
use qubit_codec_text::{
CharsetCodec,
CharsetEncodeProbe,
Codec,
Charset,
Utf8,
Utf8Codec,
};
let codec = Utf8Codec;
assert_eq!(Charset::UTF_8, codec.charset());
assert_eq!(Utf8::MAX_UNITS_PER_CHAR, codec.max_units_per_value().get());
let mut output = [0_u8; Utf8::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-8")
};
assert_eq!(('é', written), (value, consumed.get()));Implementations§
Trait Implementations§
Source§impl CharsetCodec for Utf8Codec
impl CharsetCodec for Utf8Codec
Source§impl CharsetEncodeProbe for Utf8Codec
impl CharsetEncodeProbe for Utf8Codec
Source§fn encode_len(&self, ch: char, _index: usize) -> CharsetEncodeResult<usize>
fn encode_len(&self, ch: char, _index: usize) -> CharsetEncodeResult<usize>
Source§impl Codec for Utf8Codec
impl Codec for Utf8Codec
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 Utf8Codec
impl Eq for Utf8Codec
impl StructuralPartialEq for Utf8Codec
Auto Trait Implementations§
impl Freeze for Utf8Codec
impl RefUnwindSafe for Utf8Codec
impl Send for Utf8Codec
impl Sync for Utf8Codec
impl Unpin for Utf8Codec
impl UnsafeUnpin for Utf8Codec
impl UnwindSafe for Utf8Codec
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