pub struct KeyChord {
pub key: KeyKind,
pub mods: KeyMods,
}Expand description
Canonical, stack-allocated representation of one chord.
Copy so call sites can pass it freely without lifetime
gymnastics; Hash + Eq so it works as a HashMap key in
the keymap trie. Memory: 8 bytes (1-byte mod bitfield + 1-byte
discriminant + a 4-byte char or 1-byte SpecialKey, padded).
Parse one chord with str::parse (FromStr), a sequence with
parse_chord_sequence; Display writes the canonical notation.
§Examples
use lattice_protocol::{ChordParseError, KeyChord, KeyKind, KeyMods, SpecialKey};
let chord: KeyChord = "<C-S-Tab>".parse().unwrap();
assert_eq!(chord.key, KeyKind::Special(SpecialKey::Tab));
assert_eq!(chord.mods, KeyMods::CTRL | KeyMods::SHIFT);
assert_eq!(chord.to_string(), "<C-S-Tab>");
// `<` and a bare space are escaped when printed.
assert_eq!(KeyChord::char('<').to_string(), "<lt>");
assert_eq!(KeyChord::char(' ').to_string(), "<Space>");
// `FromStr` wants exactly one chord.
assert!(matches!("ab".parse::<KeyChord>(), Err(ChordParseError::BodyTooLong { .. })));Fields§
§key: KeyKindWhich key was pressed.
mods: KeyModsModifiers held with it. For a letter, Shift is encoded in the case of
KeyKind::Char instead, so this carries no SHIFT bit.
Implementations§
Source§impl KeyChord
impl KeyChord
Sourcepub const fn new(key: KeyKind, mods: KeyMods) -> KeyChord
pub const fn new(key: KeyKind, mods: KeyMods) -> KeyChord
Build directly from kind + mods. Useful for tests +
internal callers; production callers go through the
renderer-specific adapter (lattice_ui_tui::chord::from_event
for the TUI, the analogous function in the future GPUI
adapter).
Sourcepub const fn ctrl(c: char) -> KeyChord
pub const fn ctrl(c: char) -> KeyChord
Ctrl-modified character. Letter case is normalised by the
caller; convention is lowercase (<C-c>, not <C-C>).
Sourcepub const fn special(k: SpecialKey) -> KeyChord
pub const fn special(k: SpecialKey) -> KeyChord
Special key with no modifiers.
Trait Implementations§
impl Copy for KeyChord
impl Eq for KeyChord
impl StructuralPartialEq for KeyChord
Source§impl WitBoundary for KeyChord
impl WitBoundary for KeyChord
Auto Trait Implementations§
impl Freeze for KeyChord
impl RefUnwindSafe for KeyChord
impl Send for KeyChord
impl Sync for KeyChord
impl Unpin for KeyChord
impl UnsafeUnpin for KeyChord
impl UnwindSafe for KeyChord
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
§fn into_maybe_undefined(self) -> MaybeUndefined<T>
fn into_maybe_undefined(self) -> MaybeUndefined<T>
§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> ResetDiscriminant<T> for Twhere
T: Copy,
impl<T> ResetDiscriminant<T> for Twhere
T: Copy,
§fn discriminant(&self) -> T
fn discriminant(&self) -> T
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more