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) const 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.pad(self.as_str())
75 }
76}
77
78impl core::fmt::Debug for EncodedSin {
79 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
80 write!(f, "EncodedSin({:?})", self.as_str())
81 }
82}
83
84impl PartialEq for EncodedSin {
89 fn eq(&self, other: &Self) -> bool {
90 self.buf == other.buf
91 }
92}
93
94impl Eq for EncodedSin {}
95
96impl core::hash::Hash for EncodedSin {
97 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
98 self.buf.hash(state);
99 }
100}
101
102impl PartialOrd for EncodedSin {
103 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
104 Some(self.cmp(other))
105 }
106}
107
108impl Ord for EncodedSin {
109 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
110 self.buf.cmp(&other.buf)
111 }
112}
113
114impl PartialEq<str> for EncodedSin {
115 fn eq(&self, other: &str) -> bool {
116 self.as_str() == other
117 }
118}
119
120impl PartialEq<&str> for EncodedSin {
121 fn eq(&self, other: &&str) -> bool {
122 self.as_str() == *other
123 }
124}
125
126impl PartialEq<EncodedSin> for str {
127 fn eq(&self, other: &EncodedSin) -> bool {
128 self == other.as_str()
129 }
130}
131
132impl PartialEq<EncodedSin> for &str {
133 fn eq(&self, other: &EncodedSin) -> bool {
134 *self == other.as_str()
135 }
136}