struct RawVecInner<A: Allocator = Global> {
ptr: Unique<u8>,
cap: UsizeNoHighBit,
alloc: A,
}raw_vec_internals)Expand description
Like a RawVec, but only generic over the allocator, not the type.
As such, all the methods need the layout passed-in as a parameter.
Having this separation reduces the amount of code we need to monomorphize, as most operations don’t need the actual type, just its layout.
Fields§
§ptr: Unique<u8>raw_vec_internals)cap: UsizeNoHighBitraw_vec_internals)Never used for ZSTs; it’s capacity()’s responsibility to return usize::MAX in that case.
§Safety
cap must be in the 0..=isize::MAX range.
alloc: Araw_vec_internals)Implementations§
Source§impl RawVecInner<Global>
impl RawVecInner<Global>
fn with_capacity(capacity: usize, elem_layout: Layout) -> Self
raw_vec_internals)Source§impl<A: Allocator> RawVecInner<A>
impl<A: Allocator> RawVecInner<A>
const fn new_in(alloc: A, align: Alignment) -> Self
raw_vec_internals)fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self
raw_vec_internals)fn try_with_capacity_in( capacity: usize, alloc: A, elem_layout: Layout, ) -> Result<Self, TryReserveError>
raw_vec_internals)fn with_capacity_zeroed_in( capacity: usize, alloc: A, elem_layout: Layout, ) -> Self
raw_vec_internals)fn try_allocate_in( capacity: usize, init: AllocInit, alloc: A, elem_layout: Layout, ) -> Result<Self, TryReserveError>
raw_vec_internals)unsafe fn from_raw_parts_in(ptr: *mut u8, cap: UsizeNoHighBit, alloc: A) -> Self
raw_vec_internals)unsafe fn from_nonnull_in( ptr: NonNull<u8>, cap: UsizeNoHighBit, alloc: A, ) -> Self
raw_vec_internals)const fn ptr<T>(&self) -> *mut T
raw_vec_internals)const fn non_null<T>(&self) -> NonNull<T>
raw_vec_internals)const fn capacity(&self, elem_size: usize) -> usize
raw_vec_internals)fn allocator(&self) -> &A
raw_vec_internals)Sourceunsafe fn current_memory(
&self,
elem_layout: Layout,
) -> Option<(NonNull<u8>, Layout)>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn current_memory( &self, elem_layout: Layout, ) -> Option<(NonNull<u8>, Layout)>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout)
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout)
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn grow_one(&mut self, elem_layout: Layout)
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn grow_one(&mut self, elem_layout: Layout)
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn try_reserve(
&mut self,
len: usize,
additional: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn try_reserve( &mut self, len: usize, additional: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn reserve_exact(
&mut self,
len: usize,
additional: usize,
elem_layout: Layout,
)
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn reserve_exact( &mut self, len: usize, additional: usize, elem_layout: Layout, )
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn try_reserve_exact(
&mut self,
len: usize,
additional: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn try_reserve_exact( &mut self, len: usize, additional: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment
Sourceunsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout)
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout)
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignmentcapmust be less than or equal toself.capacity(elem_layout.size())
fn needs_to_grow( &self, len: usize, additional: usize, elem_layout: Layout, ) -> bool
raw_vec_internals)unsafe fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize)
raw_vec_internals)Sourceunsafe fn grow_amortized(
&mut self,
len: usize,
additional: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn grow_amortized( &mut self, len: usize, additional: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment- The sum of
lenandadditionalmust be greater than the current capacity
Sourceunsafe fn grow_exact(
&mut self,
len: usize,
additional: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn grow_exact( &mut self, len: usize, additional: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignment- The sum of
lenandadditionalmust be greater than the current capacity
Sourceunsafe fn finish_grow(
&self,
cap: usize,
elem_layout: Layout,
) -> Result<NonNull<[u8]>, TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn finish_grow( &self, cap: usize, elem_layout: Layout, ) -> Result<NonNull<[u8]>, TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignmentcapmust be greater than the current capacity
Sourceunsafe fn shrink(
&mut self,
cap: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn shrink( &mut self, cap: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)§Safety
elem_layoutmust be valid forself, i.e. it must be the sameelem_layoutused to initially constructselfelem_layout’s size must be a multiple of its alignmentcapmust be less than or equal toself.capacity(elem_layout.size())
Sourceunsafe fn shrink_unchecked(
&mut self,
cap: usize,
elem_layout: Layout,
) -> Result<(), TryReserveError>
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn shrink_unchecked( &mut self, cap: usize, elem_layout: Layout, ) -> Result<(), TryReserveError>
raw_vec_internals)shrink, but without the capacity check.
This is split out so that shrink can inline the check, since it
optimizes out in things like shrink_to_fit, without needing to
also inline all this code, as doing that ends up failing the
vec-shrink-panic codegen test when shrink_to_fit ends up being too
big for LLVM to be willing to inline.
§Safety
cap <= self.capacity()
Sourceunsafe fn deallocate(&mut self, elem_layout: Layout)
🔬This is a nightly-only experimental API. (raw_vec_internals)
unsafe fn deallocate(&mut self, elem_layout: Layout)
raw_vec_internals)§Safety
This function deallocates the owned allocation, but does not update ptr or cap to
prevent double-free or use-after-free. Essentially, do not do anything with the caller
after this function returns.
Ideally this function would take self by move, but it cannot because it exists to be
called from a Drop impl.
Auto Trait Implementations§
impl<A> Freeze for RawVecInner<A>where
A: Freeze,
impl<A> RefUnwindSafe for RawVecInner<A>where
A: RefUnwindSafe,
impl<A> Send for RawVecInner<A>where
A: Send,
impl<A> Sync for RawVecInner<A>where
A: Sync,
impl<A> Unpin for RawVecInner<A>where
A: Unpin,
impl<A> UnwindSafe for RawVecInner<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const SIZE: usize = _
#[doc(hidden)] const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)] const ALIGN: usize = _
#[doc(hidden)] const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more