@@ -417,7 +417,8 @@ where
417417
418418 /// Inserts an element into the `HashTable` with the given hash value, but
419419 /// 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.
421422 ///
422423 /// # Examples
423424 ///
@@ -430,9 +431,10 @@ where
430431 /// let mut v = HashTable::new();
431432 /// let hasher = DefaultHashBuilder::default();
432433 /// 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());
434436 /// 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() );
436438 /// assert!(!v.is_empty());
437439 /// # }
438440 /// # fn main() {
@@ -444,13 +446,15 @@ where
444446 & mut self ,
445447 hash : u64 ,
446448 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+ }
454458 }
455459
456460 /// Clears the table, removing all values.
0 commit comments