haystack_core/kinds/
xstr.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6pub struct XStr {
7 pub type_name: String,
8 pub val: String,
9}
10
11impl XStr {
12 pub fn new(type_name: impl Into<String>, val: impl Into<String>) -> Self {
13 Self {
14 type_name: type_name.into(),
15 val: val.into(),
16 }
17 }
18}
19
20impl fmt::Display for XStr {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 write!(f, "{}(\"{}\")", self.type_name, self.val)
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29
30 #[test]
31 fn xstr_display() {
32 let x = XStr::new("Color", "red");
33 assert_eq!(x.to_string(), "Color(\"red\")");
34 }
35
36 #[test]
37 fn xstr_equality() {
38 assert_eq!(XStr::new("Color", "red"), XStr::new("Color", "red"));
39 assert_ne!(XStr::new("Color", "red"), XStr::new("Color", "blue"));
40 }
41}