@@ -205,14 +205,8 @@ impl InlineTable {
205205 match self . items . entry ( key. into ( ) ) {
206206 indexmap:: map:: Entry :: Occupied ( mut entry) => {
207207 // 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 ( ) ) ;
216210 entry. get_mut ( ) . value = scratch;
217211
218212 InlineEntry :: Occupied ( InlineOccupiedEntry { entry } )
@@ -229,14 +223,8 @@ impl InlineTable {
229223 match self . items . entry ( key. get ( ) . into ( ) ) {
230224 indexmap:: map:: Entry :: Occupied ( mut entry) => {
231225 // 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 ( ) ) ;
240228 entry. get_mut ( ) . value = scratch;
241229
242230 InlineEntry :: Occupied ( InlineOccupiedEntry { entry } )
@@ -285,7 +273,7 @@ impl InlineTable {
285273 let kv = TableKeyValue :: new ( Key :: new ( key) , Item :: Value ( value) ) ;
286274 self . items
287275 . insert ( InternalString :: from ( key) , kv)
288- . and_then ( |kv| kv. value . into_value ( ) . ok ( ) )
276+ . map ( |kv| kv. value . into_value ( ) )
289277 }
290278
291279 /// Inserts a key-value pair into the map.
@@ -294,21 +282,20 @@ impl InlineTable {
294282 self . items
295283 . insert ( InternalString :: from ( key. get ( ) ) , kv)
296284 . filter ( |kv| kv. value . is_value ( ) )
297- . map ( |kv| kv. value . into_value ( ) . unwrap ( ) )
285+ . map ( |kv| kv. value . into_value ( ) )
298286 }
299287
300288 /// Removes an item given the key.
301289 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 ( ) )
305291 }
306292
307293 /// Removes a key from the map, returning the stored key and value if the key was previously in the map.
308294 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| {
310296 let key = kv. key ;
311- kv. value . into_value ( ) . ok ( ) . map ( |value| ( key, value) )
297+ let value = kv. value . into_value ( ) ;
298+ ( key, value)
312299 } )
313300 }
314301}
@@ -351,7 +338,7 @@ impl IntoIterator for InlineTable {
351338 self . items
352339 . into_iter ( )
353340 . 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 ( ) ) ) ,
355342 )
356343 }
357344}
@@ -395,6 +382,12 @@ impl TableLike for InlineTable {
395382 . map ( |( _, kv) | ( kv. key . as_mut ( ) , & mut kv. value ) ) ,
396383 )
397384 }
385+ fn len ( & self ) -> usize {
386+ self . len ( )
387+ }
388+ fn is_empty ( & self ) -> bool {
389+ self . is_empty ( )
390+ }
398391 fn get < ' s > ( & ' s self , key : & str ) -> Option < & ' s Item > {
399392 self . items . get ( key) . map ( |kv| & kv. value )
400393 }
@@ -405,8 +398,7 @@ impl TableLike for InlineTable {
405398 self . contains_key ( key)
406399 }
407400 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 )
410402 }
411403 fn remove ( & mut self , key : & str ) -> Option < Item > {
412404 self . remove ( key) . map ( Item :: Value )
@@ -526,12 +518,12 @@ impl<'a> InlineOccupiedEntry<'a> {
526518 pub fn insert ( & mut self , value : Value ) -> Value {
527519 let mut value = Item :: Value ( value) ;
528520 std:: mem:: swap ( & mut value, & mut self . entry . get_mut ( ) . value ) ;
529- value. into_value ( ) . unwrap ( )
521+ value. into_value ( )
530522 }
531523
532524 /// Takes the value out of the entry, and returns it
533525 pub fn remove ( self ) -> Value {
534- self . entry . shift_remove ( ) . value . into_value ( ) . unwrap ( )
526+ self . entry . shift_remove ( ) . value . into_value ( )
535527 }
536528}
537529
0 commit comments