Skip to main content

register_runtime_event

Function register_runtime_event 

Source
pub fn register_runtime_event(
    name: impl Into<String>,
    doc: impl Into<String>,
    source: impl Into<String>,
) -> bool
Expand description

Register a runtime (plugin-defined) event. Idempotent by name (a re-register overwrites — a plugin reload refreshes its doc). Returns false and records nothing if the name collides with a BUILT-IN event: a plugin must not shadow a native event (its subscribers would be ambiguous). Also returns false if the registry lock is poisoned.

The registry is process-wide, so it is shared by every editor instance (and every test) in the process.

§Examples

use lattice_protocol::event_registry::{
    all_events, event_info_by_name, register_runtime_event, unregister_runtime_event,
};

assert!(register_runtime_event(
    "demo-plugin.file-indexed",
    "A file finished indexing.",
    "plugin:demo-plugin",
));
let info = event_info_by_name("demo-plugin.file-indexed").unwrap();
assert!(!info.builtin);
assert_eq!(info.source, "plugin:demo-plugin");
assert!(all_events().iter().any(|e| e.name == "demo-plugin.file-indexed"));

unregister_runtime_event("demo-plugin.file-indexed"); // plugin unload
assert!(event_info_by_name("demo-plugin.file-indexed").is_none());