hadris_common/str/
utf16.rs1use crate::types::{
2 endian::{Endian, LittleEndian},
3 number::U16,
4};
5
6#[repr(C)]
7#[derive(Debug, Clone, Copy)]
8pub struct FixedUtf16Str<const N: usize> {
9 data: [U16<LittleEndian>; N],
10}
11
12impl<const N: usize> FixedUtf16Str<N> {
13 pub fn to_string(&self) -> Result<String, ()> {
14 let data = self.data.iter().map(|c| c.get() as u8).collect::<Vec<u8>>();
16 String::from_utf8(data).map_err(|_| ())
17 }
18}
19
20#[cfg(feature = "bytemuck")]
21unsafe impl<const N: usize> bytemuck::Pod for FixedUtf16Str<N> {}
22#[cfg(feature = "bytemuck")]
23unsafe impl<const N: usize> bytemuck::Zeroable for FixedUtf16Str<N> {}