use crate::ngstr::prelude::*;
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Cesu8Str {
inner: [u8],
}
impl Cesu8Str {
impl_str_encoding_meths!(base, Cesu8Str, any, "CESU-8");
impl_str_encoding_meths!(str, Cesu8Str, any, "CESU-8");
}
impl Cesu8Str {
pub const ENCODE_NUL: bool = false;
pub const NUL_TERM: bool = false;
pub(crate) const unsafe fn _from_bytes_unchecked(bytes: &[u8]) -> &Self {
&*(bytes as *const [u8] as *const Self)
}
pub(crate) const fn _raw_bytes(&self) -> &[u8] {
unsafe { &*(self as *const Self as *const [u8]) }
}
}
impl ToOwned for Cesu8Str {
type Owned = Cesu8String;
fn to_owned(&self) -> Self::Owned {
unsafe { Self::Owned::from_bytes_unchecked(self.inner.to_vec()) }
}
}
impl Default for &Cesu8Str {
fn default() -> Self {
const EMPTY: &[u8] = &[];
unsafe { Cesu8Str::from_bytes_unchecked(EMPTY) }
}
}