Skip to content

Commit 4dd48d7

Browse files
committed
always check lang id list length
1 parent e7bc3f0 commit 4dd48d7

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/device_builder.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
164164
"Not support more than 16 \"manufacturer\"s"
165165
);
166166

167-
// do list length check only if user already specify "extra_lang_ids"
168-
let num_extra_langs = self.config.extra_lang_ids.as_ref().map(|langs| langs.len()).unwrap_or(0);
169-
167+
let num_extra_langs = self
168+
.config
169+
.extra_lang_ids
170+
.as_ref()
171+
.map(|langs| langs.len())
172+
.unwrap_or(0);
173+
170174
assert!(
171175
manufacturer_ls.len() == num_extra_langs + 1,
172176
"The length of \"manufacturer\" list should be one more than \"extra_lang_ids\" list",
173-
)
174-
177+
);
175178

176179
self.config.manufacturer = Some(manufacturer_ls);
177180

@@ -195,13 +198,17 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
195198
"Not support more than 16 \"product\"s"
196199
);
197200

198-
// do list length check only if user already specify "extra_lang_ids"
199-
if let Some(extra_lang_ids) = self.config.extra_lang_ids {
200-
assert!(
201-
product_ls.len() == extra_lang_ids.len() + 1,
202-
"The length of \"product\" list should be one more than \"extra_lang_ids\" list",
203-
)
204-
}
201+
let num_extra_langs = self
202+
.config
203+
.extra_lang_ids
204+
.as_ref()
205+
.map(|langs| langs.len())
206+
.unwrap_or(0);
207+
208+
assert!(
209+
product_ls.len() == num_extra_langs + 1,
210+
"The length of \"product\" list should be one more than \"extra_lang_ids\" list",
211+
);
205212

206213
self.config.product = Some(product_ls);
207214

@@ -225,13 +232,17 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
225232
"Not support more than 16 \"serial_number\"s"
226233
);
227234

228-
// do list length check only if user already specify "extra_lang_ids"
229-
if let Some(extra_lang_ids) = self.config.extra_lang_ids {
230-
assert!(
231-
serial_number_ls.len() == extra_lang_ids.len() + 1,
232-
"The length of \"serial_number\" list should be one more than \"extra_lang_ids\" list",
233-
)
234-
}
235+
let num_extra_langs = self
236+
.config
237+
.extra_lang_ids
238+
.as_ref()
239+
.map(|langs| langs.len())
240+
.unwrap_or(0);
241+
242+
assert!(
243+
serial_number_ls.len() == num_extra_langs + 1,
244+
"The length of \"serial_number\" list should be one more than \"extra_lang_ids\" list",
245+
);
235246

236247
self.config.serial_number = Some(serial_number_ls);
237248

0 commit comments

Comments
 (0)