#[derive(Debug, Clone)]
pub enum RegistryEvent {
Register {
type_name: &'static str,
},
RegisterCompleted {
type_name: &'static str,
},
Get {
type_name: &'static str,
found: bool,
},
Contains {
type_name: &'static str,
found: bool,
},
Clear {},
}
impl std::fmt::Display for RegistryEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RegistryEvent::Register { type_name } => {
write!(f, "register {{ type_name: {} }}", type_name)
}
RegistryEvent::RegisterCompleted { type_name } => {
write!(f, "register_completed {{ type_name: {} }}", type_name)
}
RegistryEvent::Get { type_name, found } => {
write!(f, "get {{ type_name: {}, found: {} }}", type_name, found)
}
RegistryEvent::Contains { type_name, found } => {
write!(
f,
"contains {{ type_name: {}, found: {} }}",
type_name, found
)
}
RegistryEvent::Clear {} => write!(f, "Clearing the Registry"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_display_register() {
let ev = RegistryEvent::Register { type_name: "i32" };
assert_eq!(ev.to_string(), "register { type_name: i32 }");
}
#[test]
fn test_display_register_completed() {
let ev = RegistryEvent::RegisterCompleted { type_name: "i32" };
assert_eq!(ev.to_string(), "register_completed { type_name: i32 }");
}
#[test]
fn test_display_get() {
let ev = RegistryEvent::Get {
type_name: "String",
found: true,
};
assert_eq!(ev.to_string(), "get { type_name: String, found: true }");
}
#[test]
fn test_display_contains() {
let ev = RegistryEvent::Contains {
type_name: "u8",
found: false,
};
assert_eq!(ev.to_string(), "contains { type_name: u8, found: false }");
}
#[test]
fn test_display_clear() {
let ev = RegistryEvent::Clear {};
assert_eq!(ev.to_string(), "Clearing the Registry");
}
}