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: UsizeNoHighBit

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: 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) -> Self
fn 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) -> Self
const unsafe fn from_raw_parts_in(ptr: *mut u8, cap: UsizeNoHighBit, alloc: A) -> Self
const unsafe fn from_nonnull_in(ptr: NonNull<u8>, cap: UsizeNoHighBit, alloc: A) -> Self
const fn ptr<T>(&self) -> *mut T
const fn non_null<T>(&self) -> NonNull<T>
const fn capacity(&self, elem_size: usize) -> usize
const fn allocator(&self) -> &A
const unsafe fn current_memory(&self, elem_layout: Layout) -> Option<(NonNull<u8>, Layout)>

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
unsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout)

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
unsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout)

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • cap must be less than or equal to self.capacity(elem_layout.size())
unsafe fn try_shrink_to_fit(&mut self, cap: usize, elem_layout: Layout) -> Result<(), TryReserveError>

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • cap must be less than or equal to self.capacity(elem_layout.size())
const fn needs_to_grow(&self, len: usize, additional: usize, elem_layout: Layout) -> bool
const 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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • The sum of len and additional must be greater than the current capacity
unsafe fn shrink(&mut self, cap: usize, elem_layout: Layout) -> Result<(), TryReserveError>

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • cap must be less than or equal to self.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 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()

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 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.

impl<A: ~const Allocator> RawVecInner<A>

const fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self
const 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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_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_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • The sum of len and additional must be greater than the current capacity
const unsafe fn finish_grow(&self, cap: usize, elem_layout: Layout) -> Result<NonNull<[u8]>, TryReserveError>

Safety

  • elem_layout must be valid for self, i.e. it must be the same elem_layout used to initially construct self
  • elem_layout's size must be a multiple of its alignment
  • cap must 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) -> T

Returns the argument unchanged.

impl<T> SizeHint for RawVecInner<A> where T: ?Sized,

fn lower_bound(&self) -> usize
fn 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) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>