singleton_registry/
registry_event.rs1#[derive(Debug, Clone)]
20pub enum RegistryEvent {
21 Register {
24 type_name: &'static str,
26 },
27
28 RegisterCompleted {
30 type_name: &'static str,
32 },
33
34 Get {
36 type_name: &'static str,
38 found: bool,
40 },
41
42 Contains {
44 type_name: &'static str,
46 found: bool,
48 },
49
50 Clear {},
52}
53
54impl std::fmt::Display for RegistryEvent {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 match self {
57 RegistryEvent::Register { type_name } => {
58 write!(f, "register {{ type_name: {} }}", type_name)
59 }
60 RegistryEvent::RegisterCompleted { type_name } => {
61 write!(f, "register_completed {{ type_name: {} }}", type_name)
62 }
63 RegistryEvent::Get { type_name, found } => {
64 write!(f, "get {{ type_name: {}, found: {} }}", type_name, found)
65 }
66 RegistryEvent::Contains { type_name, found } => {
67 write!(
68 f,
69 "contains {{ type_name: {}, found: {} }}",
70 type_name, found
71 )
72 }
73 RegistryEvent::Clear {} => write!(f, "Clearing the Registry"),
74 }
75 }
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_display_register() {
84 let ev = RegistryEvent::Register { type_name: "i32" };
85 assert_eq!(ev.to_string(), "register { type_name: i32 }");
86 }
87
88 #[test]
89 fn test_display_register_completed() {
90 let ev = RegistryEvent::RegisterCompleted { type_name: "i32" };
91 assert_eq!(ev.to_string(), "register_completed { type_name: i32 }");
92 }
93
94 #[test]
95 fn test_display_get() {
96 let ev = RegistryEvent::Get {
97 type_name: "String",
98 found: true,
99 };
100 assert_eq!(ev.to_string(), "get { type_name: String, found: true }");
101 }
102
103 #[test]
104 fn test_display_contains() {
105 let ev = RegistryEvent::Contains {
106 type_name: "u8",
107 found: false,
108 };
109 assert_eq!(ev.to_string(), "contains { type_name: u8, found: false }");
110 }
111
112 #[test]
113 fn test_display_clear() {
114 let ev = RegistryEvent::Clear {};
115 assert_eq!(ev.to_string(), "Clearing the Registry");
116 }
117}