Lines Matching full:capacity

79 /// capacity of the vector (the number of elements that currently fit into the vector), its length
97 /// without re-allocation. For ZSTs `self.layout`'s capacity is zero. However, it is legal for the
100 /// - `self.len()` is always less than or equal to `self.capacity()`.
108 /// Note: This isn't quite the same as `Self::capacity`, which in contrast returns the number of
181 pub const fn capacity(&self) -> usize { in capacity() function
199 /// - `additional` must be less than or equal to `self.capacity - self.len`.
204 debug_assert!(additional <= self.capacity() - self.len()); in inc_len()
288 // - `layout` is an empty `ArrayLayout` (zero capacity) in new()
299 /// Returns a slice of `MaybeUninit<T>` for the remaining spare capacity of the vector.
302 // - `self.len` is smaller than `self.capacity` by the type invariant and hence, the in spare_capacity_mut()
307 // SAFETY: The memory between `self.len` and `self.capacity` is guaranteed to be allocated in spare_capacity_mut()
309 unsafe { slice::from_raw_parts_mut(ptr, self.capacity() - self.len) } in spare_capacity_mut()
327 // SAFETY: The call to `reserve` was successful, so the capacity is at least one greater in push()
335 /// Fails if the vector does not have capacity for the new element.
349 if self.len() < self.capacity() { in push_within_capacity()
350 // SAFETY: The length is less than the capacity. in push_within_capacity()
362 /// The length must be less than the capacity.
370 // by 1. We also know that the new length is <= capacity because the caller guarantees that in push_within_capacity_unchecked()
371 // the length is less than the capacity at the beginning of this function. in push_within_capacity_unchecked()
377 /// Fails if the vector does not have capacity for the new element. Panics if the index is out
405 if len >= self.capacity() { in insert_within_capacity()
409 // SAFETY: This is in bounds since `index <= len < capacity`. in insert_within_capacity()
414 // Since the length is less than the capacity, both ranges are in bounds of the allocation. in insert_within_capacity()
491 /// Creates a new [`Vec`] instance with at least the given capacity.
498 /// assert!(v.capacity() >= 20);
501 pub fn with_capacity(capacity: usize, flags: Flags) -> Result<Self, AllocError> { in with_capacity()
504 v.reserve(capacity, flags)?; in with_capacity()
509 /// Creates a `Vec<T, A>` from a pointer, a length and a capacity using the allocator `A`.
543 /// - `ptr` must point to memory with a size of at least `size_of::<T>() * capacity` bytes.
545 /// - `length` must be less than or equal to `capacity`.
550 pub unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Self { in from_raw_parts()
554 // SAFETY: By the safety requirements of this function, `capacity * size_of::<T>()` is in from_raw_parts()
556 unsafe { ArrayLayout::new_unchecked(capacity) } in from_raw_parts()
571 /// Consumes the `Vec<T, A>` and returns its raw components `pointer`, `length` and `capacity`.
579 let capacity = me.capacity(); in into_raw_parts() localVariable
581 (ptr, len, capacity) in into_raw_parts()
586 /// Note that this method has no effect on the allocated capacity
604 /// Ensures that the capacity exceeds the length by at least `additional` elements.
613 /// let cap = v.capacity();
617 /// let new_cap = v.capacity();
624 let cap = self.capacity(); in reserve()
631 // The capacity is already `usize::MAX` for ZSTs, we can't go higher. in reserve()
666 /// This has no effect on the capacity and will not allocate.
701 /// assert!(v.capacity() >= 4);
707 // INVARIANT: The first `len` elements of the spare capacity are valid values, and as we in drain_all()
757 // - `self.len() + n < self.capacity()` due to the call to reserve above, in extend_with()
788 // - `self.len() + other.len() <= self.capacity()` is guaranteed by the preceding `reserve` in extend_from_slice()
1187 // - `cap` is either the original capacity or, after shrinking the buffer, equal to `len`. in collect()