Skip to content

Commit

Permalink
list length check only if user already specify "extra_lang_ids"
Browse files Browse the repository at this point in the history
  • Loading branch information
eZioPan committed Jul 27, 2023
1 parent 4dd48d7 commit cf693a0
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions src/device_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,13 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
"Not support more than 16 \"manufacturer\"s"
);

let num_extra_langs = self
.config
.extra_lang_ids
.as_ref()
.map(|langs| langs.len())
.unwrap_or(0);

assert!(
manufacturer_ls.len() == num_extra_langs + 1,
"The length of \"manufacturer\" list should be one more than \"extra_lang_ids\" list",
);
// do list length check only if user already specify "extra_lang_ids"
if let Some(extra_lang_ids) = self.config.extra_lang_ids {
assert!(
manufacturer_ls.len() == extra_lang_ids.len() + 1,
"The length of \"product\" list should be one more than \"extra_lang_ids\" list",
)
}

self.config.manufacturer = Some(manufacturer_ls);

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

let num_extra_langs = self
.config
.extra_lang_ids
.as_ref()
.map(|langs| langs.len())
.unwrap_or(0);

assert!(
product_ls.len() == num_extra_langs + 1,
"The length of \"product\" list should be one more than \"extra_lang_ids\" list",
);
// do list length check only if user already specify "extra_lang_ids"
if let Some(extra_lang_ids) = self.config.extra_lang_ids {
assert!(
product_ls.len() == extra_lang_ids.len() + 1,
"The length of \"product\" list should be one more than \"extra_lang_ids\" list",
)
}

self.config.product = Some(product_ls);

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

let num_extra_langs = self
.config
.extra_lang_ids
.as_ref()
.map(|langs| langs.len())
.unwrap_or(0);

assert!(
serial_number_ls.len() == num_extra_langs + 1,
"The length of \"serial_number\" list should be one more than \"extra_lang_ids\" list",
);
// do list length check only if user already specify "extra_lang_ids"
if let Some(extra_lang_ids) = self.config.extra_lang_ids {
assert!(
serial_number_ls.len() == extra_lang_ids.len() + 1,
"The length of \"serial_number\" list should be one more than \"extra_lang_ids\" list",
)
}

self.config.serial_number = Some(serial_number_ls);

Expand Down

0 comments on commit cf693a0

Please sign in to comment.