CustomKey

Struct CustomKey 

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

Custom key definition

Implementations§

Source§

impl CustomKey

Source

pub fn new(name: &str) -> Self

Create a new custom key with the given name

Examples found in repository?
examples/advanced_parsing.rs (line 33)
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_platform_code( &mut self, platform: Platform, code: usize, ) -> &mut Self

Add a platform-specific code mapping for this key

Examples found in repository?
examples/advanced_parsing.rs (line 35)
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 name(&self) -> &str

Get the key name

Source

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

Get the platform-specific code for this key

Source

pub fn codes(&self) -> &HashMap<Platform, usize>

Get all platform codes for this key

Trait Implementations§

Source§

impl Clone for CustomKey

Source§

fn clone(&self) -> CustomKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CustomKey

Source§

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

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

impl Hash for CustomKey

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CustomKey

Source§

fn eq(&self, other: &CustomKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for CustomKey

Source§

impl StructuralPartialEq for CustomKey

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.