Skip to content

Commit 195b7d8

Browse files
ithinueleldruin
authored andcommitted
Improve clippy coverage
1 parent d6eaf93 commit 195b7d8

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

.github/workflows/rustfmt.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ jobs:
1616
components: rustfmt
1717
- run: cargo fmt --all -- --check
1818
- run: cargo clippy --all-features
19+
- run: cargo clippy --features defmt
20+
- run: cargo clippy --features control-buffer-256
21+
- run: cargo clippy

src/descriptor/lang_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ pub enum LangID {
349349
MN_MONG_MN = 0x0C50,
350350
DZ_BT = 0x0C51,
351351
TMZ_MA = 0x0C5F,
352-
QUZ_PE = 0x0C6b,
352+
QUZ_PE = 0x0C6B,
353353
LOCALE_CUSTOM_UNSPECIFIED = 0x1000,
354354
AR_LY = 0x1001,
355355
ZH_SG = 0x1004,

src/device.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -606,32 +606,28 @@ impl<B: UsbBus> UsbDevice<'_, B> {
606606
}
607607
};
608608

609-
lang_id_list
610-
.iter()
611-
.fuse()
612-
.position(|list_lang_id| match *list_lang_id {
613-
Some(list_lang_id) if req_lang_id == list_lang_id => true,
614-
_ => false,
615-
})
616-
.or_else(|| {
617-
// Since we construct the list of full supported lang_ids previously,
618-
// we can safely reject requests which ask for other lang_id.
619-
#[cfg(feature = "defmt")]
620-
defmt::warn!(
621-
"Receive unknown LANGID {:#06X}, reject the request",
622-
req_lang_id
623-
);
624-
None
625-
})
626-
.and_then(|lang_id_list_index| {
627-
match index {
628-
1 => config.manufacturer,
629-
2 => config.product,
630-
3 => config.serial_number,
631-
_ => unreachable!(),
632-
}
633-
.map(|str_list| str_list[lang_id_list_index])
634-
})
609+
let position =
610+
lang_id_list.iter().fuse().position(|list_lang_id| {
611+
matches!(*list_lang_id, Some(list_lang_id) if req_lang_id == list_lang_id)
612+
});
613+
#[cfg(feature = "defmt")]
614+
if position.is_none() {
615+
// Since we construct the list of full supported lang_ids previously,
616+
// we can safely reject requests which ask for other lang_id.
617+
defmt::warn!(
618+
"Receive unknown LANGID {:#06X}, reject the request",
619+
req_lang_id
620+
);
621+
}
622+
position.and_then(|lang_id_list_index| {
623+
match index {
624+
1 => config.manufacturer,
625+
2 => config.product,
626+
3 => config.serial_number,
627+
_ => unreachable!(),
628+
}
629+
.map(|str_list| str_list[lang_id_list_index])
630+
})
635631
} else {
636632
// for other custom STRINGs
637633

src/device_builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
114114
///
115115
/// Default: (none)
116116
pub fn set_extra_lang_ids(mut self, extra_lang_ids: &'a [LangID]) -> Self {
117-
if extra_lang_ids.len() == 0 {
117+
if extra_lang_ids.is_empty() {
118118
self.config.extra_lang_ids = None;
119119
return self;
120120
}
@@ -154,7 +154,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
154154
///
155155
/// Default: (none)
156156
pub fn manufacturer(mut self, manufacturer_ls: &'a [&'a str]) -> Self {
157-
if manufacturer_ls.len() == 0 {
157+
if manufacturer_ls.is_empty() {
158158
self.config.manufacturer = None;
159159
return self;
160160
}
@@ -184,7 +184,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
184184
///
185185
/// Default: (none)
186186
pub fn product(mut self, product_ls: &'a [&'a str]) -> Self {
187-
if product_ls.len() == 0 {
187+
if product_ls.is_empty() {
188188
self.config.product = None;
189189
return self;
190190
}
@@ -214,7 +214,7 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
214214
///
215215
/// Default: (none)
216216
pub fn serial_number(mut self, serial_number_ls: &'a [&'a str]) -> Self {
217-
if serial_number_ls.len() == 0 {
217+
if serial_number_ls.is_empty() {
218218
self.config.serial_number = None;
219219
return self;
220220
}

0 commit comments

Comments
 (0)