use crate::identifier::Identifier;
#[derive(Clone, Copy)]
pub struct EncodedSin {
buf: [u8; 1],
}
impl EncodedSin {
#[must_use]
pub(crate) fn from_identifier(id: Identifier) -> Self {
Self {
buf: [id.letter().to_ascii(id.side())],
}
}
#[must_use]
pub fn as_str(&self) -> &str {
debug_assert!(
self.buf.is_ascii(),
"EncodedSin must contain only ASCII bytes"
);
core::str::from_utf8(&self.buf).unwrap_or("")
}
}
impl core::ops::Deref for EncodedSin {
type Target = str;
fn deref(&self) -> &str {
self.as_str()
}
}
impl AsRef<str> for EncodedSin {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl core::fmt::Display for EncodedSin {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
impl core::fmt::Debug for EncodedSin {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "EncodedSin({:?})", self.as_str())
}
}
impl PartialEq<str> for EncodedSin {
fn eq(&self, other: &str) -> bool {
self.as_str() == other
}
}
impl PartialEq<&str> for EncodedSin {
fn eq(&self, other: &&str) -> bool {
self.as_str() == *other
}
}
impl PartialEq<EncodedSin> for str {
fn eq(&self, other: &EncodedSin) -> bool {
self == other.as_str()
}
}
impl PartialEq<EncodedSin> for &str {
fn eq(&self, other: &EncodedSin) -> bool {
*self == other.as_str()
}
}