keymap_derive
This crate provides a derive macro #[derive(KeyMap)] for Rust enums to easily generate implementations for:
TryFrom<KeyMap>andTryFrom<Vec<KeyMap>>: Allowing conversion from parsed key events to your enum variants.KeyMapConfig<YourEnum>: Providing the derived keybindings as default configurations.
This is part of the keymap-rs workspace.
Usage
Add keymap with the derive feature to your Cargo.toml:
[]
= { = "0.5", = ["derive"] } # Check for the latest version
Then, use the KeyMap derive macro on your enum:
use KeyMap; // For TryFrom<KeyMap> and parse_keymap
use KeyMap; // For the derive macro itself
Attributes
#[key("key1", "key2", ..., description = "Human-readable description")]:- Specifies one or more key sequences that map to this enum variant.
- The
descriptionis optional but recommended, especially when usingDerivedConfigas it will be part of the defaultItemgenerated.
For more advanced usage, including how these derived defaults can be customized by users with DerivedConfig, please see the main keymap-rs README.