@@ -118,6 +118,30 @@ impl<T> RawVec<T, Global> {
118
118
RawVec :: from_raw_parts ( slice. as_mut_ptr ( ) , slice. len ( ) )
119
119
}
120
120
}
121
+
122
+ /// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
123
+ ///
124
+ /// Note that this will correctly reconstitute any `cap` changes
125
+ /// that may have been performed. (See description of type for details.)
126
+ ///
127
+ /// # Safety
128
+ ///
129
+ /// * `len` must be greater than or equal to the most recently requested capacity, and
130
+ /// * `len` must be less than or equal to `self.capacity()`.
131
+ ///
132
+ /// Note, that the requested capacity and `self.capacity()` could differ, as
133
+ /// an allocator could overallocate and return a greater memory block than requested.
134
+ pub unsafe fn into_box ( self , len : usize ) -> Box < [ MaybeUninit < T > ] > {
135
+ // Sanity-check one half of the safety requirement (we cannot check the other half).
136
+ debug_assert ! (
137
+ len <= self . capacity( ) ,
138
+ "`len` must be smaller than or equal to `self.capacity()`"
139
+ ) ;
140
+
141
+ let me = ManuallyDrop :: new ( self ) ;
142
+ let slice = slice:: from_raw_parts_mut ( me. ptr ( ) as * mut MaybeUninit < T > , len) ;
143
+ Box :: from_raw ( slice)
144
+ }
121
145
}
122
146
123
147
impl < T , A : AllocRef > RawVec < T , A > {
@@ -520,32 +544,6 @@ where
520
544
Ok ( memory)
521
545
}
522
546
523
- impl < T > RawVec < T , Global > {
524
- /// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
525
- ///
526
- /// Note that this will correctly reconstitute any `cap` changes
527
- /// that may have been performed. (See description of type for details.)
528
- ///
529
- /// # Safety
530
- ///
531
- /// * `len` must be greater than or equal to the most recently requested capacity, and
532
- /// * `len` must be less than or equal to `self.capacity()`.
533
- ///
534
- /// Note, that the requested capacity and `self.capacity()` could differ, as
535
- /// an allocator could overallocate and return a greater memory block than requested.
536
- pub unsafe fn into_box ( self , len : usize ) -> Box < [ MaybeUninit < T > ] > {
537
- // Sanity-check one half of the safety requirement (we cannot check the other half).
538
- debug_assert ! (
539
- len <= self . capacity( ) ,
540
- "`len` must be smaller than or equal to `self.capacity()`"
541
- ) ;
542
-
543
- let me = ManuallyDrop :: new ( self ) ;
544
- let slice = slice:: from_raw_parts_mut ( me. ptr ( ) as * mut MaybeUninit < T > , len) ;
545
- Box :: from_raw ( slice)
546
- }
547
- }
548
-
549
547
unsafe impl < #[ may_dangle] T , A : AllocRef > Drop for RawVec < T , A > {
550
548
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
551
549
fn drop ( & mut self ) {
0 commit comments