use core::fmt::Write;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck::Zeroable, bytemuck::Pod)]
#[repr(transparent)]
pub struct AsciiArray<const N: usize>(pub [u8; N]);
impl<const N: usize> Default for AsciiArray<N> {
#[inline]
#[must_use]
fn default() -> Self {
Self([0_u8; N])
}
}
impl<const N: usize> core::fmt::Debug for AsciiArray<N> {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_char('\"')?;
for ch in self.0.iter().copied().map(|u| u as char) {
f.write_char(ch)?;
}
f.write_char('\"')?;
Ok(())
}
}
impl<const N: usize> core::fmt::Display for AsciiArray<N> {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
for ch in self.0.iter().copied().map(|u| u as char) {
f.write_char(ch)?;
}
Ok(())
}
}
impl<const N: usize> From<[u8; N]> for AsciiArray<N> {
#[inline]
#[must_use]
fn from(array: [u8; N]) -> Self {
Self(array)
}
}
impl<const N: usize> PartialEq<&str> for AsciiArray<N> {
#[inline]
#[must_use]
fn eq(&self, other: &&str) -> bool {
self.0.as_slice() == other.as_bytes()
}
}