pub struct CustomKeyMap { /* private fields */ }Expand description
Custom key mapping manager
Implementations§
Source§impl CustomKeyMap
impl CustomKeyMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty custom key mapping manager
Examples found in repository?
examples/advanced_parsing.rs (line 32)
9fn main() {
10 println!("=== 高级解析功能示例 ===\n");
11
12 // 1. 灵活的分隔符支持
13 println!("1. 灵活的分隔符支持:");
14 let shortcuts = ["ctrl+c", "ctrl-c", "ctrl c", "ctrl+shift+esc"];
15 for shortcut in shortcuts {
16 if let Ok(parsed) = parse_shortcut_flexible(shortcut) {
17 println!(" '{}' -> {}", shortcut, parsed);
18 }
19 }
20
21 // 2. 快捷方式序列
22 println!("\n2. 快捷方式序列:");
23 let sequence = "ctrl+c, ctrl+v, ctrl+z, ctrl+y";
24 if let Ok(shortcuts) = parse_shortcut_sequence(sequence) {
25 for (i, shortcut) in shortcuts.iter().enumerate() {
26 println!(" {}: {}", i + 1, shortcut);
27 }
28 }
29
30 // 3. 自定义键映射
31 println!("\n3. 自定义键映射:");
32 let mut custom_map = CustomKeyMap::new();
33 let mut custom_key = CustomKey::new("MyCustomKey");
34 custom_key
35 .add_platform_code(Platform::Windows, 0x100)
36 .add_platform_code(Platform::Linux, 500);
37
38 if custom_map.add_key(custom_key).is_ok() {
39 println!(" 自定义键添加成功");
40 }
41
42 println!("\n示例完成!");
43}Sourcepub fn add_key(&mut self, key: CustomKey) -> Result<(), KeyParseError>
pub fn add_key(&mut self, key: CustomKey) -> Result<(), KeyParseError>
Add a custom key to the mapping
§Errors
Returns KeyParseError::DuplicateCustomKey if a key with the same name already exists
Examples found in repository?
examples/advanced_parsing.rs (line 38)
9fn main() {
10 println!("=== 高级解析功能示例 ===\n");
11
12 // 1. 灵活的分隔符支持
13 println!("1. 灵活的分隔符支持:");
14 let shortcuts = ["ctrl+c", "ctrl-c", "ctrl c", "ctrl+shift+esc"];
15 for shortcut in shortcuts {
16 if let Ok(parsed) = parse_shortcut_flexible(shortcut) {
17 println!(" '{}' -> {}", shortcut, parsed);
18 }
19 }
20
21 // 2. 快捷方式序列
22 println!("\n2. 快捷方式序列:");
23 let sequence = "ctrl+c, ctrl+v, ctrl+z, ctrl+y";
24 if let Ok(shortcuts) = parse_shortcut_sequence(sequence) {
25 for (i, shortcut) in shortcuts.iter().enumerate() {
26 println!(" {}: {}", i + 1, shortcut);
27 }
28 }
29
30 // 3. 自定义键映射
31 println!("\n3. 自定义键映射:");
32 let mut custom_map = CustomKeyMap::new();
33 let mut custom_key = CustomKey::new("MyCustomKey");
34 custom_key
35 .add_platform_code(Platform::Windows, 0x100)
36 .add_platform_code(Platform::Linux, 500);
37
38 if custom_map.add_key(custom_key).is_ok() {
39 println!(" 自定义键添加成功");
40 }
41
42 println!("\n示例完成!");
43}Sourcepub fn remove_key(&mut self, name: &str) -> Option<CustomKey>
pub fn remove_key(&mut self, name: &str) -> Option<CustomKey>
Remove a custom key by name
Sourcepub fn parse_by_name(&self, name: &str) -> Option<&CustomKey>
pub fn parse_by_name(&self, name: &str) -> Option<&CustomKey>
Parse a custom key by name
Sourcepub fn parse_by_code(
&self,
code: usize,
platform: Platform,
) -> Option<&CustomKey>
pub fn parse_by_code( &self, code: usize, platform: Platform, ) -> Option<&CustomKey>
Parse a custom key by code and platform
Sourcepub fn to_code(&self, key: &CustomKey, platform: Platform) -> Option<usize>
pub fn to_code(&self, key: &CustomKey, platform: Platform) -> Option<usize>
Convert a custom key to a platform-specific code
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
Check if a custom key with the given name exists
Trait Implementations§
Source§impl Debug for CustomKeyMap
impl Debug for CustomKeyMap
Source§impl Default for CustomKeyMap
impl Default for CustomKeyMap
Source§fn default() -> CustomKeyMap
fn default() -> CustomKeyMap
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CustomKeyMap
impl RefUnwindSafe for CustomKeyMap
impl Send for CustomKeyMap
impl Sync for CustomKeyMap
impl Unpin for CustomKeyMap
impl UnwindSafe for CustomKeyMap
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
Mutably borrows from an owned value. Read more