1use crate::identifier::Identifier;
4
5#[derive(Clone, Copy)]
28pub struct EncodedSin {
29 buf: [u8; 1],
30}
31
32impl EncodedSin {
33 #[must_use]
36 pub(crate) fn from_identifier(id: Identifier) -> Self {
37 Self {
38 buf: [id.letter().to_ascii(id.side())],
39 }
40 }
41
42 #[must_use]
44 pub fn as_str(&self) -> &str {
45 debug_assert!(
46 self.buf.is_ascii(),
47 "EncodedSin must contain only ASCII bytes"
48 );
49 core::str::from_utf8(&self.buf).unwrap_or("")
52 }
53}
54
55impl core::ops::Deref for EncodedSin {
56 type Target = str;
57
58 fn deref(&self) -> &str {
59 self.as_str()
60 }
61}
62
63impl AsRef<str> for EncodedSin {
64 fn as_ref(&self) -> &str {
65 self.as_str()
66 }
67}
68
69impl core::fmt::Display for EncodedSin {
70 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str(self.as_str())
72 }
73}
74
75impl core::fmt::Debug for EncodedSin {
76 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 write!(f, "EncodedSin({:?})", self.as_str())
78 }
79}
80
81impl PartialEq<str> for EncodedSin {
82 fn eq(&self, other: &str) -> bool {
83 self.as_str() == other
84 }
85}
86
87impl PartialEq<&str> for EncodedSin {
88 fn eq(&self, other: &&str) -> bool {
89 self.as_str() == *other
90 }
91}
92
93impl PartialEq<EncodedSin> for str {
94 fn eq(&self, other: &EncodedSin) -> bool {
95 self == other.as_str()
96 }
97}
98
99impl PartialEq<EncodedSin> for &str {
100 fn eq(&self, other: &EncodedSin) -> bool {
101 *self == other.as_str()
102 }
103}