1use std::fmt::{Debug, Display};
2
3use smol_str::SmolStr;
4
5#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Identifier {
7 mic: SmolStr,
9
10 symbol: SmolStr,
12}
13
14impl Display for Identifier {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 f.write_fmt(format_args!("{}:{}", self.mic, self.symbol))
17 }
18}
19
20impl Identifier {
21 pub fn new<S>(mic: S, symbol: S) -> Self
22 where
23 S: Into<SmolStr>,
24 {
25 Self {
26 mic: mic.into(),
27 symbol: symbol.into(),
28 }
29 }
30
31 #[must_use]
32 pub fn mic(&self) -> &SmolStr {
33 &self.mic
34 }
35
36 #[must_use]
37 pub fn symbol(&self) -> &SmolStr {
38 &self.symbol
39 }
40}
41
42#[cfg(test)]
43mod test {
44 use std::collections::{BTreeSet, HashSet};
45
46 use super::Identifier;
47
48 #[test]
49 fn test_display() {
50 let id = Identifier::new("XASX", "ANZ");
51 assert_eq!(id.to_string(), "XASX:ANZ");
52 }
53
54 #[test]
55 fn test_hash() {
56 let mut set = HashSet::<Identifier>::new();
57 set.insert(Identifier::new("XASX", "ANZ"));
58 }
59
60 #[test]
61 fn test_btree() {
62 let mut set = BTreeSet::<Identifier>::new();
63 set.insert(Identifier::new("XASX", "ANZ"));
64 }
65}