Struct zerovec::ule::CharULE [−][src]
#[repr(transparent)]pub struct CharULE(_);
Expand description
A u8 array of little-endian data corresponding to a Unicode code point.
The bytes of a CharULE
are guaranteed to represent a little-endian-encoded u32 that is a
valid char
and can be converted without validation.
Examples
Convert a char
to a CharULE
and back again:
use zerovec::ule::{ULE, AsULE, CharULE};
let c1 = '𑄃';
let ule = c1.as_unaligned();
assert_eq!(CharULE::as_byte_slice(&[ule]), &[0x03, 0x11, 0x01, 0x00]);
let c2 = char::from_unaligned(ule);
assert_eq!(c1, c2);
Attempt to parse invalid bytes to a CharULE
:
use zerovec::ule::{ULE, CharULE};
let bytes: &[u8] = &[0xFF, 0xFF, 0xFF, 0xFF];
CharULE::parse_byte_slice(bytes).expect_err("Invalid bytes");
Trait Implementations
type Error = ULEError<CharTryFromError>
type Error = ULEError<CharTryFromError>
The error that occurs if a byte array is not valid for this ULE.
Validates a byte slice, &[u8]
. Read more
Parses a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime. Read more
Takes a byte slice, &[u8]
, and return it as &[Self]
with the same lifetime, assuming
that this byte slice has previously been run through Self::parse_byte_slice()
with
success. Read more
Auto Trait Implementations
impl RefUnwindSafe for CharULE
impl UnwindSafe for CharULE
Blanket Implementations
Mutably borrows from an owned value. Read more