@@ -417,7 +417,8 @@ where
417
417
418
418
/// Inserts an element into the `HashTable` with the given hash value, but
419
419
/// without checking whether an equivalent element already exists within
420
- /// the table. If there is insufficient capacity, then this returns None.
420
+ /// the table. If there is insufficient capacity, then this returns an
421
+ /// error holding the provided value.
421
422
///
422
423
/// # Examples
423
424
///
@@ -430,9 +431,10 @@ where
430
431
/// let mut v = HashTable::new();
431
432
/// let hasher = DefaultHashBuilder::default();
432
433
/// let hasher = |val: &_| hasher.hash_one(val);
433
- /// assert!(v.insert_unique_within_capacity(hasher(&1), 1).is_none());
434
+ /// assert!(v.insert_unique_within_capacity(hasher(&1), 1).is_err());
435
+ /// assert!(v.is_empty());
434
436
/// v.reserve(1, hasher);
435
- /// v.insert_unique_within_capacity(hasher(&1), 1);
437
+ /// assert!( v.insert_unique_within_capacity(hasher(&1), 1).is_ok() );
436
438
/// assert!(!v.is_empty());
437
439
/// # }
438
440
/// # fn main() {
@@ -444,13 +446,15 @@ where
444
446
& mut self ,
445
447
hash : u64 ,
446
448
value : T ,
447
- ) -> Option < OccupiedEntry < ' _ , T , A > > {
448
- let bucket = self . raw . insert_within_capacity ( hash, value) ?;
449
- Some ( OccupiedEntry {
450
- hash,
451
- bucket,
452
- table : self ,
453
- } )
449
+ ) -> Result < OccupiedEntry < ' _ , T , A > , T > {
450
+ match self . raw . insert_within_capacity ( hash, value) {
451
+ Some ( bucket) => Ok ( OccupiedEntry {
452
+ hash,
453
+ bucket,
454
+ table : self ,
455
+ } ) ,
456
+ None => Err ( value) ,
457
+ }
454
458
}
455
459
456
460
/// Clears the table, removing all values.
0 commit comments