@@ -216,10 +216,7 @@ impl Core {
216
216
self . instructions [ index] = value;
217
217
}
218
218
219
- pub fn add_labels < T > ( & mut self , index : usize , labels : Vec < T > ) -> Result < ( ) , String >
220
- where
221
- T : Into < String > ,
222
- {
219
+ pub fn add_label ( & mut self , index : usize , label : String ) -> Result < ( ) , String > {
223
220
if index > self . instructions . len ( ) {
224
221
return Err ( format ! (
225
222
"Address {} is not valid for core of size {}" ,
@@ -228,18 +225,13 @@ impl Core {
228
225
) ) ;
229
226
}
230
227
231
- for label in labels {
232
- match self . labels . entry ( label. into ( ) ) {
233
- Entry :: Occupied ( entry) => {
234
- return Err ( format ! ( "Label '{}' already exists" , entry. key( ) ) ) ;
235
- }
236
- Entry :: Vacant ( entry) => {
237
- entry. insert ( index) ;
238
- }
228
+ match self . labels . entry ( label) {
229
+ Entry :: Occupied ( entry) => Err ( format ! ( "Label '{}' already exists" , entry. key( ) ) ) ,
230
+ Entry :: Vacant ( entry) => {
231
+ entry. insert ( index) ;
232
+ Ok ( ( ) )
239
233
}
240
234
}
241
-
242
- Ok ( ( ) )
243
235
}
244
236
245
237
pub fn label_address ( & self , label : & str ) -> Option < usize > {
@@ -427,13 +419,13 @@ mod tests {
427
419
fn labels ( ) {
428
420
let mut core = Core :: new ( 200 ) ;
429
421
430
- core. add_labels ( 123 , vec ! [ "baz" ] ) . expect ( "Should add label " ) ;
431
- core. add_labels ( 0 , vec ! [ "foo" , "bar" ] )
432
- . expect ( "Should add two labels " ) ;
422
+ core. add_label ( 123 , "baz" . into ( ) ) . expect ( "Should add baz " ) ;
423
+ core. add_label ( 0 , "foo" . into ( ) ) . expect ( "Should add foo" ) ;
424
+ core . add_label ( 0 , "bar" . into ( ) ) . expect ( "Should add bar " ) ;
433
425
434
- core. add_labels ( 256 , vec ! [ "goblin" ] )
426
+ core. add_label ( 256 , "goblin" . into ( ) )
435
427
. expect_err ( "Should fail to add labels > 200" ) ;
436
- core. add_labels ( 5 , vec ! [ "baz" ] )
428
+ core. add_label ( 5 , "baz" . into ( ) )
437
429
. expect_err ( "Should fail to add duplicate label" ) ;
438
430
439
431
assert_eq ! ( core. label_address( "foo" ) . unwrap( ) , 0 ) ;
0 commit comments