Skip to main content

ActionHandlerRegistry

Struct ActionHandlerRegistry 

Source
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

Source

pub fn new() -> Self

Construct an empty registry.

Source

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.)

Source

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.

Trait Implementations§

Source§

impl Debug for ActionHandlerRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ActionHandlerRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more