File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1007,8 +1007,23 @@ impl<T> RawTable<T> {
1007
1007
/// on the `RawDrain`, we have to make the `drain` method unsafe.
1008
1008
#[ cfg_attr( feature = "inline-more" , inline) ]
1009
1009
pub unsafe fn drain ( & mut self ) -> RawDrain < ' _ , T > {
1010
+ let iter = self . iter ( ) ;
1011
+ self . drain_iter_from ( iter)
1012
+ }
1013
+
1014
+ /// Returns an iterator which removes all elements from the table without
1015
+ /// freeing the memory. It is up to the caller to ensure that the `RawTable`
1016
+ /// outlives the `RawDrain`. Because we cannot make the `next` method unsafe
1017
+ /// on the `RawDrain`, we have to make the `drain` method unsafe.
1018
+ ///
1019
+ /// Iteration starts at the provided iterator's current location.
1020
+ ///
1021
+ /// This method panics if the given iterator does not cover all items remaining in the table.
1022
+ #[ cfg_attr( feature = "inline-more" , inline) ]
1023
+ pub unsafe fn drain_iter_from ( & mut self , iter : RawIter < T > ) -> RawDrain < ' _ , T > {
1024
+ debug_assert_eq ! ( iter. len( ) , self . len( ) ) ;
1010
1025
RawDrain {
1011
- iter : self . iter ( ) ,
1026
+ iter,
1012
1027
table : ManuallyDrop :: new ( mem:: replace ( self , Self :: new ( ) ) ) ,
1013
1028
orig_table : NonNull :: from ( self ) ,
1014
1029
marker : PhantomData ,
You can’t perform that action at this time.
0 commit comments