From 659b1779e2c24fe4c8acf8b91dae066d46743e64 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 1 May 2019 16:36:26 -0700 Subject: usb: remove pointless Options in UsbRequestSetup The get_type and get_direction helpers return Options, even though they can only possibly return a non-None value; all bit patterns of the fields they are interpreting are defined. Drop the Options and return the enum values directly to simplify callers and remove dead code. Fix up a typo ("recipienet" -> "recipient") while we're in the neighborhood. BUG=chromium:831850 TEST=Test adb in Crostini Change-Id: Ie26a1ed1c15f5f17b5ae80be78ce5f8ff51fab28 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/1593713 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: kokoro Reviewed-by: Zach Reizner --- usb_util/src/types.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'usb_util') diff --git a/usb_util/src/types.rs b/usb_util/src/types.rs index 0c7250d..eaebc70 100644 --- a/usb_util/src/types.rs +++ b/usb_util/src/types.rs @@ -142,31 +142,29 @@ impl UsbRequestSetup { } /// Get type of request. - pub fn get_type(&self) -> Option { + pub fn get_type(&self) -> ControlRequestType { let ty = (self.request_type & CONTROL_REQUEST_TYPE) >> CONTROL_REQUEST_TYPE_OFFSET; match ty { - 0 => Some(ControlRequestType::Standard), - 1 => Some(ControlRequestType::Class), - 2 => Some(ControlRequestType::Vendor), - 3 => Some(ControlRequestType::Reserved), - _ => None, + 0 => ControlRequestType::Standard, + 1 => ControlRequestType::Class, + 2 => ControlRequestType::Vendor, + _ => ControlRequestType::Reserved, } } /// Get request direction. - pub fn get_direction(&self) -> Option { + pub fn get_direction(&self) -> ControlRequestDataPhaseTransferDirection { let dir = (self.request_type & DATA_PHASE_DIRECTION) >> DATA_PHASE_DIRECTION_OFFSET; match dir { - 0 => Some(ControlRequestDataPhaseTransferDirection::HostToDevice), - 1 => Some(ControlRequestDataPhaseTransferDirection::DeviceToHost), - _ => None, + 0 => ControlRequestDataPhaseTransferDirection::HostToDevice, + _ => ControlRequestDataPhaseTransferDirection::DeviceToHost, } } /// Get recipient of this control transfer. pub fn get_recipient(&self) -> ControlRequestRecipient { - let recipienet = self.request_type & REQUEST_RECIPIENT_TYPE; - match recipienet { + let recipient = self.request_type & REQUEST_RECIPIENT_TYPE; + match recipient { 0 => ControlRequestRecipient::Device, 1 => ControlRequestRecipient::Interface, 2 => ControlRequestRecipient::Endpoint, -- cgit 1.4.1