@@ -205,14 +205,8 @@ impl InlineTable {
205
205
match self . items . entry ( key. into ( ) ) {
206
206
indexmap:: map:: Entry :: Occupied ( mut entry) => {
207
207
// Ensure it is a `Value` to simplify `InlineOccupiedEntry`'s code.
208
- let scratch = std:: mem:: take ( & mut entry. get_mut ( ) . value ) ;
209
- let scratch = Item :: Value (
210
- scratch
211
- . into_value ( )
212
- // HACK: `Item::None` is a corner case of a corner case, let's just pick a
213
- // "safe" value
214
- . unwrap_or_else ( |_| Value :: InlineTable ( Default :: default ( ) ) ) ,
215
- ) ;
208
+ let scratch = std:: mem:: replace ( & mut entry. get_mut ( ) . value , crate :: value ( 0 ) ) ;
209
+ let scratch = Item :: Value ( scratch. into_value ( ) ) ;
216
210
entry. get_mut ( ) . value = scratch;
217
211
218
212
InlineEntry :: Occupied ( InlineOccupiedEntry { entry } )
@@ -229,14 +223,8 @@ impl InlineTable {
229
223
match self . items . entry ( key. get ( ) . into ( ) ) {
230
224
indexmap:: map:: Entry :: Occupied ( mut entry) => {
231
225
// Ensure it is a `Value` to simplify `InlineOccupiedEntry`'s code.
232
- let scratch = std:: mem:: take ( & mut entry. get_mut ( ) . value ) ;
233
- let scratch = Item :: Value (
234
- scratch
235
- . into_value ( )
236
- // HACK: `Item::None` is a corner case of a corner case, let's just pick a
237
- // "safe" value
238
- . unwrap_or_else ( |_| Value :: InlineTable ( Default :: default ( ) ) ) ,
239
- ) ;
226
+ let scratch = std:: mem:: replace ( & mut entry. get_mut ( ) . value , crate :: value ( 0 ) ) ;
227
+ let scratch = Item :: Value ( scratch. into_value ( ) ) ;
240
228
entry. get_mut ( ) . value = scratch;
241
229
242
230
InlineEntry :: Occupied ( InlineOccupiedEntry { entry } )
@@ -285,7 +273,7 @@ impl InlineTable {
285
273
let kv = TableKeyValue :: new ( Key :: new ( key) , Item :: Value ( value) ) ;
286
274
self . items
287
275
. insert ( InternalString :: from ( key) , kv)
288
- . and_then ( |kv| kv. value . into_value ( ) . ok ( ) )
276
+ . map ( |kv| kv. value . into_value ( ) )
289
277
}
290
278
291
279
/// Inserts a key-value pair into the map.
@@ -294,21 +282,20 @@ impl InlineTable {
294
282
self . items
295
283
. insert ( InternalString :: from ( key. get ( ) ) , kv)
296
284
. filter ( |kv| kv. value . is_value ( ) )
297
- . map ( |kv| kv. value . into_value ( ) . unwrap ( ) )
285
+ . map ( |kv| kv. value . into_value ( ) )
298
286
}
299
287
300
288
/// Removes an item given the key.
301
289
pub fn remove ( & mut self , key : & str ) -> Option < Value > {
302
- self . items
303
- . shift_remove ( key)
304
- . and_then ( |kv| kv. value . into_value ( ) . ok ( ) )
290
+ self . items . shift_remove ( key) . map ( |kv| kv. value . into_value ( ) )
305
291
}
306
292
307
293
/// Removes a key from the map, returning the stored key and value if the key was previously in the map.
308
294
pub fn remove_entry ( & mut self , key : & str ) -> Option < ( Key , Value ) > {
309
- self . items . shift_remove ( key) . and_then ( |kv| {
295
+ self . items . shift_remove ( key) . map ( |kv| {
310
296
let key = kv. key ;
311
- kv. value . into_value ( ) . ok ( ) . map ( |value| ( key, value) )
297
+ let value = kv. value . into_value ( ) ;
298
+ ( key, value)
312
299
} )
313
300
}
314
301
}
@@ -351,7 +338,7 @@ impl IntoIterator for InlineTable {
351
338
self . items
352
339
. into_iter ( )
353
340
. filter ( |( _, kv) | kv. value . is_value ( ) )
354
- . map ( |( k, kv) | ( k, kv. value . into_value ( ) . unwrap ( ) ) ) ,
341
+ . map ( |( k, kv) | ( k, kv. value . into_value ( ) ) ) ,
355
342
)
356
343
}
357
344
}
@@ -395,6 +382,12 @@ impl TableLike for InlineTable {
395
382
. map ( |( _, kv) | ( kv. key . as_mut ( ) , & mut kv. value ) ) ,
396
383
)
397
384
}
385
+ fn len ( & self ) -> usize {
386
+ self . len ( )
387
+ }
388
+ fn is_empty ( & self ) -> bool {
389
+ self . is_empty ( )
390
+ }
398
391
fn get < ' s > ( & ' s self , key : & str ) -> Option < & ' s Item > {
399
392
self . items . get ( key) . map ( |kv| & kv. value )
400
393
}
@@ -405,8 +398,7 @@ impl TableLike for InlineTable {
405
398
self . contains_key ( key)
406
399
}
407
400
fn insert ( & mut self , key : & str , value : Item ) -> Option < Item > {
408
- self . insert ( key, value. into_value ( ) . unwrap ( ) )
409
- . map ( Item :: Value )
401
+ self . insert ( key, value. into_value ( ) ) . map ( Item :: Value )
410
402
}
411
403
fn remove ( & mut self , key : & str ) -> Option < Item > {
412
404
self . remove ( key) . map ( Item :: Value )
@@ -526,12 +518,12 @@ impl<'a> InlineOccupiedEntry<'a> {
526
518
pub fn insert ( & mut self , value : Value ) -> Value {
527
519
let mut value = Item :: Value ( value) ;
528
520
std:: mem:: swap ( & mut value, & mut self . entry . get_mut ( ) . value ) ;
529
- value. into_value ( ) . unwrap ( )
521
+ value. into_value ( )
530
522
}
531
523
532
524
/// Takes the value out of the entry, and returns it
533
525
pub fn remove ( self ) -> Value {
534
- self . entry . shift_remove ( ) . value . into_value ( ) . unwrap ( )
526
+ self . entry . shift_remove ( ) . value . into_value ( )
535
527
}
536
528
}
537
529
0 commit comments