singleton_registry/
registry_event.rs1#[derive(Debug, Clone)]
15pub enum RegistryEvent {
16 Register {
18 type_name: &'static str,
20 },
21
22 Get {
24 type_name: &'static str,
26 found: bool,
28 },
29
30 Contains {
32 type_name: &'static str,
34 found: bool,
36 },
37
38 Clear {},
40}
41
42impl std::fmt::Display for RegistryEvent {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 RegistryEvent::Register { type_name } => {
46 write!(f, "register {{ type_name: {} }}", type_name)
47 }
48 RegistryEvent::Get { type_name, found } => {
49 write!(f, "get {{ type_name: {}, found: {} }}", type_name, found)
50 }
51 RegistryEvent::Contains { type_name, found } => {
52 write!(
53 f,
54 "contains {{ type_name: {}, found: {} }}",
55 type_name, found
56 )
57 }
58 RegistryEvent::Clear {} => write!(f, "Clearing the Registry"),
59 }
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_display_register() {
69 let ev = RegistryEvent::Register { type_name: "i32" };
70 assert_eq!(ev.to_string(), "register { type_name: i32 }");
71 }
72
73 #[test]
74 fn test_display_get() {
75 let ev = RegistryEvent::Get {
76 type_name: "String",
77 found: true,
78 };
79 assert_eq!(ev.to_string(), "get { type_name: String, found: true }");
80 }
81
82 #[test]
83 fn test_display_contains() {
84 let ev = RegistryEvent::Contains {
85 type_name: "u8",
86 found: false,
87 };
88 assert_eq!(ev.to_string(), "contains { type_name: u8, found: false }");
89 }
90
91 #[test]
92 fn test_display_clear() {
93 let ev = RegistryEvent::Clear {};
94 assert_eq!(ev.to_string(), "Clearing the Registry");
95 }
96}