1use core::fmt;
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct IconId(String);
17
18impl IconId {
19 #[inline]
24 pub fn new(id: impl Into<String>) -> Self {
25 Self(id.into())
26 }
27
28 #[inline]
29 pub fn as_str(&self) -> &str {
30 &self.0
31 }
32
33 #[inline]
34 pub fn into_string(self) -> String {
35 self.0
36 }
37}
38
39impl fmt::Display for IconId {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 f.write_str(&self.0)
42 }
43}
44
45impl AsRef<str> for IconId {
46 fn as_ref(&self) -> &str {
47 &self.0
48 }
49}
50
51impl From<String> for IconId {
52 fn from(s: String) -> Self {
53 Self(s)
54 }
55}
56
57impl From<&str> for IconId {
58 fn from(s: &str) -> Self {
59 Self(s.to_owned())
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn round_trip() {
69 let id = IconId::new("0041 0042 0043");
70 assert_eq!(id.as_str(), "0041 0042 0043");
71 assert_eq!(id.clone().into_string(), "0041 0042 0043");
72 assert_eq!(format!("{id}"), "0041 0042 0043");
73 }
74
75 #[test]
76 fn hash_eq() {
77 use std::collections::HashSet;
78 let mut s = HashSet::new();
79 s.insert(IconId::from("x"));
80 assert!(s.contains(&IconId::from("x")));
81 assert!(!s.contains(&IconId::from("y")));
82 }
83}