pub trait KeymapReverseLookup: Send + Sync {
// Required method
fn chords_for(&self, command_name: &str) -> Vec<KeyChord>;
// Provided method
fn chords_with_source(
&self,
command_name: &str,
) -> Vec<(KeyChord, KeybindingSource)> { ... }
}Expand description
Reverse-lookup contract the keybinding annotator depends on: given a command’s canonical name, return the chord sequence(s) bound to it. Empty vec means “no binding.”
MARG.2 (2026-06-03): the lattice-host side maintains the
reverse cache (built alongside the merged keymap trie on
every bind / unbind) and supplies an implementor at
boot. Keeping the trait in lattice-completion lets the
annotator type live with the other annotators while leaving
the cache-build / invalidation logic in the host crate where
the trie lives.
The empty-vec contract is important: KeybindingAnnotator
short-circuits on empty results so commands without a bound
chord don’t get a misleading empty annotation. Implementors
should NOT return vec![] to mean “lookup failed” — return
it to mean “no binding,” same thing semantically.
MARG.3 (2026-07-15): chords_with_source returns structured
provenance alongside each chord so callers can filter by
active modes and display the source mode label. The default
impl wraps every chord from chords_for with
KeybindingSource::AlwaysOn — implementors that maintain
mode-aware caches (e.g. the host’s keymap registry) should
override this to return the real provenance.
Required Methods§
fn chords_for(&self, command_name: &str) -> Vec<KeyChord>
Provided Methods§
Sourcefn chords_with_source(
&self,
command_name: &str,
) -> Vec<(KeyChord, KeybindingSource)>
fn chords_with_source( &self, command_name: &str, ) -> Vec<(KeyChord, KeybindingSource)>
Like chords_for but returns each
chord tagged with its KeybindingSource so callers can
filter by active mode and display provenance.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".