pub struct ActionHandlerRegistry { /* private fields */ }Expand description
Wait-free registry of mode-contributed action handlers.
Stored behind an Arc and shared by reference: the host’s
chord dispatcher reads via lookup;
modes register via register during
Mode::on_activate and unregister via the returned
ActionHandlerRegistration token’s Drop impl.
§Examples
The per-buffer path: a mode registers in on_activate and keeps the token
in its Guard, so deactivation unregisters the body.
use std::sync::Arc;
use lattice_grammar::effect::{EchoLevel, Effect};
use lattice_mode::{ActionHandler, ActionHandlerRegistry};
use lattice_protocol::ids::CommandId;
let registry = Arc::new(ActionHandlerRegistry::new());
let refresh = CommandId::new(41); // resolved from "action:weather-refresh"
let body: ActionHandler = Arc::new(|ctx| {
let text = format!("refreshing buffer {}", ctx.buffer_id);
Some(Effect::Echo { level: EchoLevel::Info, text })
});
let token = registry.register(refresh, body); // lives in the mode's Guard
assert!(registry.lookup(refresh).is_some());
drop(token); // the Guard dropped: the mode deactivated
assert!(registry.lookup(refresh).is_none());Implementations§
Source§impl ActionHandlerRegistry
impl ActionHandlerRegistry
Sourcepub fn register(
self: &Arc<Self>,
action_id: CommandId,
handler: ActionHandler,
) -> ActionHandlerRegistration
pub fn register( self: &Arc<Self>, action_id: CommandId, handler: ActionHandler, ) -> ActionHandlerRegistration
Register an action handler closure for action_id.
Returns an RAII registration token; the token’s Drop
impl unregisters the handler. Modes accumulate tokens
in their Guard so deactivation drops them and the
chord falls through to “unhandled” naturally.
If a handler is already registered for action_id,
the new closure replaces it. (Modes shouldn’t collide
on CommandId in normal usage — IDs are per-action
and modes register distinct sets — but the
last-write-wins semantics keeps the substrate
behavior well-defined.)
Sourcepub fn lookup(&self, action_id: CommandId) -> Option<ActionHandler>
pub fn lookup(&self, action_id: CommandId) -> Option<ActionHandler>
Wait-free lookup. Returns a cloned Arc of the
handler closure (cheap — Arc::clone is one atomic
increment). The host’s chord dispatcher calls this
once per chord resolution; calling the returned
handler is a direct Fn invocation.