macro_rules! register_event {
($ty:ty, $name:literal, $doc:literal, $source_crate:literal $(,)?) => { ... };
}Expand description
Declare and register an event type. Generates:
- An impl of
Eventfor$tyreturning the registeredEventTypeId. - A
linkme-aggregatedEventDescriptorentry pushed intoEVENT_DESCRIPTORS.
Conventions:
$nameis the user-facing identifier ("lsp.buffer-attached"); lowercase, dot-separated, namespaced by feature.$docis the short summary:describe-eventsprints.$source_craterecords who owns the declaration; useful for:describe-events --by-crateand plugin host tooling.
§Examples
use lattice_protocol::event_registry::{Event, descriptor_by_name};
use lattice_protocol::register_event;
#[derive(Debug)]
pub struct IndexFinished {
pub files: usize,
}
register_event!(
IndexFinished,
"demo.index-finished",
"Fired when the demo indexer finishes a pass.",
"demo-crate",
);
let event = IndexFinished { files: 3 };
assert_eq!(event.event_type_id().name(), "demo.index-finished");
let desc = descriptor_by_name("demo.index-finished").unwrap();
assert_eq!(desc.source_crate, "demo-crate");
assert_eq!((desc.type_id)(), std::any::TypeId::of::<IndexFinished>());The macro can’t be invoked from within a cfg(test) module
alone – linkme requires the slice entry at the top level
of a binary’s link graph. For tests that need a registered
event, declare it at module scope.
Caller crates must add linkme as a direct dependency
(proc-macro attribute paths can’t route through re-exports).
Same constraint lattice-config callers face.