@@ -164,17 +164,13 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
164
164
"Not support more than 16 \" manufacturer\" s"
165
165
) ;
166
166
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
-
174
- assert ! (
175
- manufacturer_ls. len( ) == num_extra_langs + 1 ,
176
- "The length of \" manufacturer\" list should be one more than \" extra_lang_ids\" list" ,
177
- ) ;
167
+ // do list length check only if user already specify "extra_lang_ids"
168
+ if let Some ( extra_lang_ids) = self . config . extra_lang_ids {
169
+ assert ! (
170
+ manufacturer_ls. len( ) == extra_lang_ids. len( ) + 1 ,
171
+ "The length of \" product\" list should be one more than \" extra_lang_ids\" list" ,
172
+ )
173
+ }
178
174
179
175
self . config . manufacturer = Some ( manufacturer_ls) ;
180
176
@@ -198,17 +194,13 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
198
194
"Not support more than 16 \" product\" s"
199
195
) ;
200
196
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
- ) ;
197
+ // do list length check only if user already specify "extra_lang_ids"
198
+ if let Some ( extra_lang_ids) = self . config . extra_lang_ids {
199
+ assert ! (
200
+ product_ls. len( ) == extra_lang_ids. len( ) + 1 ,
201
+ "The length of \" product\" list should be one more than \" extra_lang_ids\" list" ,
202
+ )
203
+ }
212
204
213
205
self . config . product = Some ( product_ls) ;
214
206
@@ -232,17 +224,13 @@ impl<'a, B: UsbBus> UsbDeviceBuilder<'a, B> {
232
224
"Not support more than 16 \" serial_number\" s"
233
225
) ;
234
226
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
- ) ;
227
+ // do list length check only if user already specify "extra_lang_ids"
228
+ if let Some ( extra_lang_ids) = self . config . extra_lang_ids {
229
+ assert ! (
230
+ serial_number_ls. len( ) == extra_lang_ids. len( ) + 1 ,
231
+ "The length of \" serial_number\" list should be one more than \" extra_lang_ids\" list" ,
232
+ )
233
+ }
246
234
247
235
self . config . serial_number = Some ( serial_number_ls) ;
248
236
0 commit comments