CustomKeyMap

Struct CustomKeyMap 

Source
pub struct CustomKeyMap { /* private fields */ }
Expand description

Custom key mapping manager

Implementations§

Source§

impl CustomKeyMap

Source

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}
Source

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}
Source

pub fn remove_key(&mut self, name: &str) -> Option<CustomKey>

Remove a custom key by name

Source

pub fn parse_by_name(&self, name: &str) -> Option<&CustomKey>

Parse a custom key by name

Source

pub fn parse_by_code( &self, code: usize, platform: Platform, ) -> Option<&CustomKey>

Parse a custom key by code and platform

Source

pub fn to_code(&self, key: &CustomKey, platform: Platform) -> Option<usize>

Convert a custom key to a platform-specific code

Source

pub fn keys(&self) -> impl Iterator<Item = &CustomKey>

Get all custom keys

Source

pub fn contains_key(&self, name: &str) -> bool

Check if a custom key with the given name exists

Source

pub fn len(&self) -> usize

Get the number of custom keys

Source

pub fn is_empty(&self) -> bool

Check if there are no custom keys

Trait Implementations§

Source§

impl Debug for CustomKeyMap

Source§

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

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

impl Default for CustomKeyMap

Source§

fn default() -> CustomKeyMap

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.

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.