diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 11:39:39 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-02-18 15:30:25 +0100 |
commit | 8d9241e033e1babeccee49ab848c15edd8831516 (patch) | |
tree | 8b7eca5101f299335233038eb80da685ae1ca452 /src/hid.rs | |
parent | 7da90438dd7851f66abfa81eba2eeb36ff9c9c25 (diff) | |
download | ntw-8d9241e033e1babeccee49ab848c15edd8831516.tar.gz ntw-8d9241e033e1babeccee49ab848c15edd8831516.tar.bz2 |
Add enum_u8 macro to simplify enum conversion
We need several enums that map to a u8 value. This patch adds the
enum_u8 macro that automatically derives the From and TryFrom macros for
an enum to make these conversions easier.
As TryFrom is not stable yet, we add our own TryFrom trait.
Diffstat (limited to 'src/hid.rs')
-rw-r--r-- | src/hid.rs | 32 |
1 files changed, 11 insertions, 21 deletions
@@ -11,30 +11,20 @@ use usb_device::Result; const INTERFACE_CLASS_HID: u8 = 0x03; -#[derive(Clone, Copy, Debug, PartialEq)] -#[repr(u8)] -pub enum Subclass { - None = 0x00, - BootInterface = 0x01, -} - -impl From<Subclass> for u8 { - fn from(subclass: Subclass) -> u8 { - subclass as u8 +enum_u8! { + #[derive(Clone, Copy, Debug, PartialEq)] + pub enum Subclass { + None = 0x00, + BootInterface = 0x01, } } -#[derive(Clone, Copy, Debug, PartialEq)] -#[repr(u8)] -pub enum Protocol { - None = 0x00, - Keyboard = 0x01, - Mouse = 0x02, -} - -impl From<Protocol> for u8 { - fn from(protocol: Protocol) -> u8 { - protocol as u8 +enum_u8! { + #[derive(Clone, Copy, Debug, PartialEq)] + pub enum Protocol { + None = 0x00, + Keyboard = 0x01, + Mouse = 0x02, } } |