kbvm

Struct Keysym

Source
pub struct Keysym(pub u32);
Expand description

A keysym.

Keysyms are usually generated when a physical key is pressed. In KBVM, the process of converting key presses to keysyms is handled by the LookupTable type.

A keysym represents the logical output of a key press. For example,

  • syms::a - the lowercase letter a, usually generated when pressing the physical A key.
  • syms::A - the uppercase letter A, usually generated when pressing the physical A key while holding the physical Shift key.
  • syms::BackSpace
  • syms::Return

The syms module contains pre-defined constants for all well-known keysyms. These keysyms all have a name assigned that can be accessed by calling Keysym::name. This name is identical to the name of the constant (except that constants for keysyms that start with a digit have a _ prefix).

In addition to the keysyms from the syms module, all chars can be encoded as keysyms by calling Keysym::from_char. Most of these keysyms do not have names assigned and Keysym::name returns None.

§Formatting and Parsing

Keysyms can be created from strings by calling Keysym::from_str or Keysym::from_str_insensitive. The keysym can be turned back into a string by using the Display implementation.

The Display implementation guarantees that the output can once again be parsed by calling Keysym::from_str. It produces 3 kinds of outputs:

  • If the keysym has a name, that name is printed.
  • Otherwise, if the keysym encodes a Unicode code point, it prints Uxxxx where xxxx is the hexadecimal representation of the code point and not necessarily 4 characters long.
  • Otherwise, it prints 0xXXXXXXXX where XXXXXXXX is simply the hexadecimal representation of the u32.

This type additionally implements Debug. It produces 3 kinds of outputs:

  • If the keysym has a name, that name is printed.
  • Otherwise, if the keysym can be converted to a char via Keysym::char, that char is printed with Debug::format.
  • Otherwise, it prints 0xXXXXXXXX as for the Display implementation.

Tuple Fields§

§0: u32

Implementations§

Source§

impl Keysym

Source

pub fn all() -> Keysyms

Returns an iterator over all well-known keysyms.

See the documentation of Keysyms for more details.

Source

pub fn from_char(char: char) -> Self

Creates a keysym from a char.

§Example
let keysym = Keysym::from_char('ァ');
assert_eq!(keysym.name().unwrap(), "kana_a");
assert_eq!(keysym.char().unwrap(), 'ァ');
Source

pub fn name(self) -> Option<&'static str>

Returns the name of the keysym if the keysym is a well-known keysym.

§Example
assert_eq!(syms::kana_a.name().unwrap(), "kana_a");
Source

pub fn char(self) -> Option<char>

Returns the char corresponding to this keysym.

§Example
assert_eq!(syms::kana_a.char().unwrap(), 'ァ');
Source

pub fn from_str(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>

Creates a keysym from a case-sensitive string.

§Example
assert_eq!(Keysym::from_str("kana_a").unwrap(), syms::kana_a);
Source

pub fn from_str_insensitive(name: &(impl AsRef<[u8]> + ?Sized)) -> Option<Self>

Creates a keysym from a case-insensitive string.

If the well-known names of two keysyms differ only by casing, the keysym with the larger name is returned. Here, larger is defined in terms of str::cmp.

§Example
assert_eq!(Keysym::from_str_insensitive("A").unwrap(), syms::a);
assert_eq!(Keysym::from_str("A").unwrap(), syms::A);
Source

pub fn to_uppercase(self) -> Self

Returns the uppercase variant of this keysym.

If this keysym does not have an uppercase variant or if it already uppercase, self is returned.

Note that some Unicode code points have uppercase variants that cannot be represented as a single Unicode code point. In these cases this function also returns self. If you only about the text representation, consider first converting to char via Self::char and then using the standard library functions to do the case conversion.

§Examples
assert_eq!(syms::a.to_uppercase(), syms::A);
let u1f80 = '\u{1f80}';
assert_eq!(u1f80.to_uppercase().collect::<String>(), "\u{1f08}\u{399}");
let sym = Keysym::from_char(u1f80);
assert_eq!(sym.to_uppercase(), sym);
Source

pub fn to_lowercase(self) -> Self

Returns the lowercase variant of this keysym.

If this keysym does not have an lowercase variant or if it already lowercase, self is returned.

The warning about Unicode code points from Self::to_uppercase also applies to this function.

§Examples
assert_eq!(syms::A.to_lowercase(), syms::a);
Source

pub fn is_in_unicode_range(self) -> bool

Returns whether this keysym is in the Unicode range.

Keysyms encode Unicode code points in the range by setting the most significant byte to 0x01. This function returns whether the most significant byte is 0x01.

Note that this function does not always return true if the keysym was created with Self::from_char. Many Unicode code points are represented by well-known keysyms outside of the Unicode range.

Even if this function returns true, that does not mean that Self::char returns Some. For example Keysym(0x01_ff_ff_ff).is_in_unicode_range() returns true but 0xff_ff_ff is not a valid Unicode code point.

§Examples
assert!(!syms::A.is_in_unicode_range());
assert!(Keysym(0x01_00_00_41).is_in_unicode_range());
Source

pub fn is_not_in_unicode_range(self) -> bool

Returns the negation of Self::is_in_unicode_range.

Source

pub fn is_well_known(self) -> bool

Returns whether this keysym is well-known.

This is equivalent to Self::name returning Some.

§Examples
assert!(syms::A.is_well_known());
Source

pub fn is_not_well_known(self) -> bool

Returns the negation of Self::is_well_known.

Source

pub fn is_valid(self) -> bool

Returns whether this keysym is valid.

A keysym is valid if it is well-known or if is in the Unicode range and represents a valid Unicode code point.

§Examples
assert!(syms::A.is_valid());
assert!(!Keysym(0x01_ff_ff_ff).is_valid());
Source

pub fn is_invalid(self) -> bool

Returns the negation of Self::is_valid.

Source

pub fn is_lowercase(self) -> bool

Returns whether this is a lowercase keysym.

§Example
assert!(syms::a.is_lowercase());
assert!(!syms::A.is_lowercase());
assert!(!syms::Return.is_lowercase());
Source

pub fn is_uppercase(self) -> bool

Returns whether this is an uppercase keysym.

§Example
assert!(syms::A.is_uppercase());
assert!(!syms::a.is_uppercase());
assert!(!syms::Return.is_uppercase());
Source

pub fn is_keypad(self) -> bool

Returns whether this is a keypad keysym.

§Example
assert!(syms::KP_0.is_keypad());
assert!(!syms::a.is_keypad());
Source

pub fn is_modifier(self) -> bool

Returns whether this is a modifier keysym.

§Example
assert!(syms::Shift_L.is_modifier());
assert!(!syms::a.is_modifier());

Trait Implementations§

Source§

impl Clone for Keysym

Source§

fn clone(&self) -> Keysym

Returns a copy 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 Keysym

Source§

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

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

impl Default for Keysym

Source§

fn default() -> Keysym

Returns the “default value” for a type. Read more
Source§

impl Display for Keysym

Source§

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

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

impl FromStr for Keysym

Source§

type Err = UnknownKeysymName

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Keysym

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 Ord for Keysym

Source§

fn cmp(&self, other: &Keysym) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Keysym

Source§

fn eq(&self, other: &Keysym) -> 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 PartialOrd for Keysym

Source§

fn partial_cmp(&self, other: &Keysym) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Keysym

Source§

impl Eq for Keysym

Source§

impl StructuralPartialEq for Keysym

Auto Trait Implementations§

§

impl Freeze for Keysym

§

impl RefUnwindSafe for Keysym

§

impl Send for Keysym

§

impl Sync for Keysym

§

impl Unpin for Keysym

§

impl UnwindSafe for Keysym

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<Lhs, Rhs> IsntPartialEqExt<Lhs, Rhs> for Lhs
where Lhs: PartialEq<Rhs> + ?Sized, Rhs: ?Sized,

Source§

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

The negation of eq
Source§

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

The negation of ne
Source§

impl<Lhs, Rhs> IsntPartialOrdExt<Lhs, Rhs> for Lhs
where Lhs: PartialOrd<Rhs> + ?Sized, Rhs: ?Sized,

Source§

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

The negation of lt
Source§

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

The negation of le
Source§

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

The negation of gt
Source§

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

The negation of ge
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.