use inventory;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HandlerKind {
Command,
Query,
Notification,
}
#[derive(Debug, Clone, Copy)]
pub struct HandlerRegistration {
pub kind: HandlerKind,
pub message_type_name: fn() -> &'static str,
pub handler_type_name: fn() -> &'static str,
}
inventory::collect!(HandlerRegistration);
#[doc(hidden)]
pub mod __private {
pub use inventory;
}
#[cfg(test)]
mod tests {
use super::*;
fn test_cmd_name() -> &'static str {
"hexeract_core::registration::tests::TestCmd"
}
fn test_handler_name() -> &'static str {
"hexeract_core::registration::tests::TestHandler"
}
inventory::submit!(HandlerRegistration {
kind: HandlerKind::Command,
message_type_name: test_cmd_name,
handler_type_name: test_handler_name,
});
#[test]
fn inventory_collects_registrations_submitted_in_tests() {
let found = inventory::iter::<HandlerRegistration>
.into_iter()
.any(|r| (r.message_type_name)().ends_with("::TestCmd"));
assert!(
found,
"registration submitted from the tests module must be visible to inventory::iter",
);
}
#[test]
fn handler_kind_is_copyable_and_comparable() {
let a = HandlerKind::Command;
let b = a;
assert_eq!(a, b);
assert_ne!(HandlerKind::Command, HandlerKind::Query);
}
}