haystack_core/kinds/
symbol.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct Symbol(pub String);
7
8impl Symbol {
9 pub fn new(val: impl Into<String>) -> Self {
10 Self(val.into())
11 }
12
13 pub fn val(&self) -> &str {
14 &self.0
15 }
16}
17
18impl fmt::Display for Symbol {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 write!(f, "^{}", self.0)
21 }
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn symbol_display() {
30 let s = Symbol::new("hot-water");
31 assert_eq!(s.to_string(), "^hot-water");
32 }
33
34 #[test]
35 fn symbol_equality() {
36 assert_eq!(Symbol::new("site"), Symbol::new("site"));
37 assert_ne!(Symbol::new("site"), Symbol::new("equip"));
38 }
39
40 #[test]
41 fn symbol_val() {
42 assert_eq!(Symbol::new("ahu").val(), "ahu");
43 }
44}