pub unsafe fn from_raw_parts(ptr: *mut T, capacity: usize) -> Self {
unsafe { Self::from_raw_parts_in(ptr, capacity, Global) }
}
- #[allow_internal_unstable(const_fn)]
+}
+
+impl<T, A: AllocRef> RawVec<T, A> {
+ /// Like `new`, but parameterized over the choice of allocator for
+ /// the returned `RawVec`.
++ #[cfg_attr(not(bootstrap), rustc_allow_const_fn_unstable(const_fn))]
++ #[cfg_attr(bootstrap, allow_internal_unstable(const_fn))]
+ pub const fn new_in(alloc: A) -> Self {
+ // `cap: 0` means "unallocated". zero-sized types are ignored.
+ Self { ptr: Unique::dangling(), cap: 0, alloc }
+ }
+
+ /// Like `with_capacity`, but parameterized over the choice of
+ /// allocator for the returned `RawVec`.
+ #[inline]
+ pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
+ Self::allocate_in(capacity, AllocInit::Uninitialized, alloc)
+ }
+
+ /// Like `with_capacity_zeroed`, but parameterized over the choice
+ /// of allocator for the returned `RawVec`.
+ #[inline]
+ pub fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self {
+ Self::allocate_in(capacity, AllocInit::Zeroed, alloc)
+ }
/// Converts a `Box<[T]>` into a `RawVec<T>`.
- pub fn from_box(slice: Box<[T]>) -> Self {
+ pub fn from_box(slice: Box<[T], A>) -> Self {
unsafe {
- let mut slice = ManuallyDrop::new(slice);
- RawVec::from_raw_parts(slice.as_mut_ptr(), slice.len())
+ let (slice, alloc) = Box::into_raw_with_alloc(slice);
+ RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc)
}
}