Struct RawVecInner
pub(in ::raw_vec) struct RawVecInner<A: Allocator = Global> { pub(in ::raw_vec) ptr: Unique<u8>, pub(in ::raw_vec) cap: UsizeNoHighBit, pub(in ::raw_vec) alloc: A }
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>cap: UsizeNoHighBitNever used for ZSTs; it's
capacity()'s responsibility to return usize::MAX in that case.Safety
capmust be in the0..=isize::MAXrange.alloc: A
Implementations
impl RawVecInner<Global>
fn with_capacity(capacity: usize, elem_layout: Layout) -> Self
impl<A: Allocator> RawVecInner<A>
const fn new_in(alloc: A, align: Alignment) -> Selffn try_with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Result<Self, TryReserveError>fn with_capacity_zeroed_in(capacity: usize, alloc: A, elem_layout: Layout) -> Selfconst unsafe fn from_raw_parts_in(ptr: *mut u8, cap: UsizeNoHighBit, alloc: A) -> Selfconst unsafe fn from_nonnull_in(ptr: NonNull<u8>, cap: UsizeNoHighBit, alloc: A) -> Selfconst fn ptr<T>(&self) -> *mut Tconst fn non_null<T>(&self) -> NonNull<T>const fn capacity(&self, elem_size: usize) -> usizeconst fn allocator(&self) -> &Aconst unsafe fn current_memory(&self, elem_layout: Layout) -> Option<(NonNull<u8>, Layout)>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
unsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout)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
unsafe fn try_reserve(&mut self, len: usize, additional: usize, elem_layout: Layout) -> Result<(), TryReserveError>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
unsafe fn reserve_exact(&mut self, len: usize, additional: usize, elem_layout: Layout)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
unsafe fn try_reserve_exact(&mut self, len: usize, additional: usize, elem_layout: Layout) -> Result<(), TryReserveError>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
unsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout)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())
unsafe fn try_shrink_to_fit(&mut self, cap: usize, elem_layout: Layout) -> Result<(), TryReserveError>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())
const fn needs_to_grow(&self, len: usize, additional: usize, elem_layout: Layout) -> boolconst unsafe fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize)unsafe fn grow_exact(&mut self, len: usize, additional: usize, elem_layout: Layout) -> Result<(), TryReserveError>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
unsafe fn shrink(&mut self, cap: usize, elem_layout: Layout) -> Result<(), TryReserveError>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())
unsafe fn shrink_unchecked(&mut self, cap: usize, elem_layout: Layout) -> Result<(), TryReserveError>shrink, but without the capacity check.This is split out so that
shrinkcan inline the check, since it optimizes out in things likeshrink_to_fit, without needing to also inline all this code, as doing that ends up failing thevec-shrink-paniccodegen test whenshrink_to_fitends up being too big for LLVM to be willing to inline.Safety
cap <= self.capacity()
impl<A: ~const Allocator> RawVecInner<A>
const unsafe fn deallocate(&mut self, elem_layout: Layout)Safety
This function deallocates the owned allocation, but does not update
ptrorcapto prevent double-free or use-after-free. Essentially, do not do anything with the caller after this function returns. Ideally this function would takeselfby move, but it cannot because it exists to be called from aDropimpl.
impl<A: ~const Allocator> RawVecInner<A>
const fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Selfconst fn try_allocate_in(capacity: usize, init: AllocInit, alloc: A, elem_layout: Layout) -> Result<Self, TryReserveError>const unsafe fn grow_one(&mut self, elem_layout: Layout)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
const unsafe fn grow_amortized(&mut self, len: usize, additional: usize, elem_layout: Layout) -> Result<(), TryReserveError>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
const unsafe fn finish_grow(&self, cap: usize, elem_layout: Layout) -> Result<NonNull<[u8]>, TryReserveError>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
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> UnsafeUnpin for RawVecInner<A>
where
A: UnsafeUnpin,
impl<A> UnwindSafe for RawVecInner<A>
where
A: UnwindSafe,
Blanket Implementations
impl<T> Any for RawVecInner<A>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for RawVecInner<A>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for RawVecInner<A>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for RawVecInner<A>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for RawVecInner<A>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for RawVecInner<A>
impl<T, U> Into<U> for RawVecInner<A>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for RawVecInner<A>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for RawVecInner<A>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>