@@ -203,7 +203,7 @@ where
203
203
unsafe { self . entries. push_unchecked( Bucket { hash, key, value } ) } ;
204
204
return Insert :: Success ( Inserted {
205
205
index: self . insert_phase_2( probe, Pos :: new( index, hash) ) ,
206
- old_value: None
206
+ old_value: None ,
207
207
} ) ;
208
208
} else if entry_hash == hash && unsafe { self . entries. get_unchecked( i) . key == key }
209
209
{
@@ -217,7 +217,7 @@ where
217
217
}
218
218
} else {
219
219
if self . entries. is_full( ) {
220
- return Insert :: Full ( ( key, value) )
220
+ return Insert :: Full ( ( key, value) ) ;
221
221
}
222
222
// empty bucket, insert here
223
223
let index = self . entries. len( ) ;
@@ -321,7 +321,7 @@ pub enum Entry<'a, K, V, const N: usize> {
321
321
/// The entry corresponding to the key `K` exists in the map
322
322
Occupied ( OccupiedEntry < ' a , K , V , N > ) ,
323
323
/// The entry corresponding to the key `K` does not exist in the map
324
- Vacant ( VacantEntry < ' a , K , V , N > )
324
+ Vacant ( VacantEntry < ' a , K , V , N > ) ,
325
325
}
326
326
327
327
/// An occupied entry which can be manipulated
@@ -332,8 +332,10 @@ pub struct OccupiedEntry<'a, K, V, const N: usize> {
332
332
core : & ' a mut CoreMap < K , V , N > ,
333
333
}
334
334
335
- impl < ' a , K , V , const N : usize > OccupiedEntry < ' a , K , V , N > where K : Eq + Hash {
336
-
335
+ impl < ' a , K , V , const N : usize > OccupiedEntry < ' a , K , V , N >
336
+ where
337
+ K : Eq + Hash ,
338
+ {
337
339
/// Gets a reference to the key that this entity corresponds to
338
340
pub fn key ( & self ) -> & K {
339
341
& self . key
@@ -348,30 +350,33 @@ impl<'a, K, V, const N: usize> OccupiedEntry<'a, K, V, N> where K: Eq + Hash {
348
350
pub fn get ( & self ) -> & V {
349
351
// SAFETY: Already checked existence at instantiation and the only mutable reference
350
352
// to the map is internally held.
351
- unsafe {
352
- & self . core . entries . get_unchecked ( self . pos ) . value
353
- }
353
+ unsafe { & self . core . entries . get_unchecked ( self . pos ) . value }
354
354
}
355
355
356
356
/// Gets a mutable reference to the value associated with this entry
357
357
pub fn get_mut ( & mut self ) -> & mut V {
358
358
// SAFETY: Already checked existence at instantiation and the only mutable reference
359
359
// to the map is internally held.
360
- unsafe { & mut self . core . entries . get_unchecked_mut ( self . pos ) . value }
360
+ unsafe { & mut self . core . entries . get_unchecked_mut ( self . pos ) . value }
361
361
}
362
362
363
363
/// Consumes this entry and yields a reference to the underlying value
364
364
pub fn into_mut ( self ) -> & ' a mut V {
365
365
// SAFETY: Already checked existence at instantiation and the only mutable reference
366
366
// to the map is internally held.
367
- unsafe { & mut self . core . entries . get_unchecked_mut ( self . pos ) . value }
367
+ unsafe { & mut self . core . entries . get_unchecked_mut ( self . pos ) . value }
368
368
}
369
369
370
370
/// Overwrites the underlying map's value with this entry's value
371
371
pub fn insert ( self , value : V ) -> V {
372
372
// SAFETY: Already checked existence at instantiation and the only mutable reference
373
373
// to the map is internally held.
374
- unsafe { mem:: replace ( & mut self . core . entries . get_unchecked_mut ( self . pos ) . value , value) }
374
+ unsafe {
375
+ mem:: replace (
376
+ & mut self . core . entries . get_unchecked_mut ( self . pos ) . value ,
377
+ value,
378
+ )
379
+ }
375
380
}
376
381
377
382
/// Removes this entry from the map and yields its value
@@ -386,8 +391,10 @@ pub struct VacantEntry<'a, K, V, const N: usize> {
386
391
hash_val : HashValue ,
387
392
core : & ' a mut CoreMap < K , V , N > ,
388
393
}
389
- impl < ' a , K , V , const N : usize > VacantEntry < ' a , K , V , N > where K : Eq + Hash {
390
-
394
+ impl < ' a , K , V , const N : usize > VacantEntry < ' a , K , V , N >
395
+ where
396
+ K : Eq + Hash ,
397
+ {
391
398
/// Get the key associated with this entry
392
399
pub fn key ( & self ) -> & K {
393
400
& self . key
@@ -416,7 +423,6 @@ impl<'a, K, V, const N: usize> VacantEntry<'a, K, V, N> where K: Eq + Hash {
416
423
}
417
424
}
418
425
}
419
-
420
426
}
421
427
422
428
/// Fixed capacity [`IndexMap`](https://docs.rs/indexmap/1/indexmap/map/struct.IndexMap.html)
@@ -598,7 +604,6 @@ where
598
604
}
599
605
}
600
606
601
-
602
607
/// Returns an entry for the corresponding key
603
608
/// ```
604
609
/// use heapless::FnvIndexMap;
@@ -621,13 +626,13 @@ where
621
626
key,
622
627
probe,
623
628
pos,
624
- core : & mut self . core
629
+ core : & mut self . core ,
625
630
} )
626
631
} else {
627
632
Entry :: Vacant ( VacantEntry {
628
633
key,
629
634
hash_val,
630
- core : & mut self . core
635
+ core : & mut self . core ,
631
636
} )
632
637
}
633
638
}
@@ -794,7 +799,7 @@ where
794
799
let hash = hash_with ( & key, & self . build_hasher ) ;
795
800
match self . core . insert ( hash, key, value) {
796
801
Insert :: Success ( inserted) => Ok ( inserted. old_value ) ,
797
- Insert :: Full ( ( k, v) ) => Err ( ( k, v) )
802
+ Insert :: Full ( ( k, v) ) => Err ( ( k, v) ) ,
798
803
}
799
804
}
800
805
@@ -1082,9 +1087,9 @@ where
1082
1087
1083
1088
#[ cfg( test) ]
1084
1089
mod tests {
1090
+ use crate :: indexmap:: Entry ;
1085
1091
use crate :: FnvIndexMap ;
1086
1092
use core:: mem;
1087
- use crate :: indexmap:: Entry ;
1088
1093
1089
1094
#[ test]
1090
1095
fn size ( ) {
@@ -1239,7 +1244,7 @@ mod tests {
1239
1244
match entry {
1240
1245
Entry :: Occupied ( o) => {
1241
1246
assert_eq ! ( ( key, value) , o. remove_entry( ) ) ;
1242
- } ,
1247
+ }
1243
1248
Entry :: Vacant ( _) => {
1244
1249
panic ! ( "Entry not found" )
1245
1250
}
@@ -1258,7 +1263,7 @@ mod tests {
1258
1263
match entry {
1259
1264
Entry :: Occupied ( o) => {
1260
1265
assert_eq ! ( value, o. remove( ) ) ;
1261
- } ,
1266
+ }
1262
1267
Entry :: Vacant ( _) => {
1263
1268
panic ! ( "Entry not found" ) ;
1264
1269
}
0 commit comments