From b3d3eed0cd31d671c3f71be3cdb1ecb81f62d1bf Mon Sep 17 00:00:00 2001 From: Amol Bhave Date: Wed, 24 Aug 2022 22:17:39 -0400 Subject: [PATCH] fields.rs: Make request_type function a const fn Make request_type function in fields.rs a const fn so that it can used to create const global variables. Test: The following code now compiles ``` const CTRL_OUT: u8 = request_type( rusb::Direction::Out, rusb::RequestType::Vendor, rusb::Recipient::Device, ); ``` --- src/fields.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fields.rs b/src/fields.rs index 678fdf4..1749c0a 100644 --- a/src/fields.rs +++ b/src/fields.rs @@ -206,7 +206,11 @@ impl std::fmt::Display for Version { /// /// rusb::request_type(Direction::In, RequestType::Standard, Recipient::Device); /// ``` -pub fn request_type(direction: Direction, request_type: RequestType, recipient: Recipient) -> u8 { +pub const fn request_type( + direction: Direction, + request_type: RequestType, + recipient: Recipient, +) -> u8 { let mut value: u8 = match direction { Direction::Out => LIBUSB_ENDPOINT_OUT, Direction::In => LIBUSB_ENDPOINT_IN,