From b049a4dc6683038ee431e492e4207fddc8549441 Mon Sep 17 00:00:00 2001 From: Oskar Gustafsson Date: Mon, 19 Nov 2018 22:59:04 +0100 Subject: [PATCH] Add ordering traits to VirtualKeyCode (#713) Motivation: This allows VirtualKeyCode variants to be stored in a BTreeSet. Unlike HashSets, BTreeSets implement Ord and Hash, allowing them to be keys in a {Hash|BTree}Maps. This is nice, e.g. when implementing keyboard shortcuts functionality, which maps a set of pressed keys to some action. --- CHANGELOG.md | 1 + src/events.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6783ab94..d0862dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - On Windows, fix issue where resizing or moving window combined with grabbing the cursor would freeze program. - On Windows, fix issue where resizing or moving window would eat `Awakened` events. - On X11, fixed a segfault when using virtual monitors with XRandR. +- Derive `Ord` and `PartialOrd` for `VirtualKeyCode` enum. # Version 0.18.0 (2018-11-07) diff --git a/src/events.rs b/src/events.rs index 6725b19a..b764bcd5 100644 --- a/src/events.rs +++ b/src/events.rs @@ -253,7 +253,7 @@ pub enum MouseScrollDelta { } /// Symbolic name for a keyboard key. -#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)] #[repr(u32)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum VirtualKeyCode {