Skip to content

Vec: rename storage_capacity to capacity and remove the const version #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Changed `stable_deref_trait` to a platform-dependent dependency.
- Changed `SortedLinkedList::pop` return type from `Result<T, ()>` to `Option<T>` to match `std::vec::pop`.
- `Vec::capacity` is no longer a `const` function.

### Fixed

Expand All @@ -56,6 +57,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed `MpMcQueue` with `mpmc_large` feature.
- Fix missing `Drop` for `MpMcQueue`

### Removed

- `Vec::storage_capacity` has been removed and `Vec::capacity` must be used instead.

## [v0.8.0] - 2023-11-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ where
/* Public API */
/// Returns the capacity of the binary heap.
pub fn capacity(&self) -> usize {
self.data.storage_capacity()
self.data.capacity()
}

/// Drops all items from the binary heap.
Expand Down
2 changes: 1 addition & 1 deletion src/linear_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
/// assert_eq!(map.capacity(), 8);
/// ```
pub fn capacity(&self) -> usize {
self.buffer.storage_capacity()
self.buffer.capacity()
}

/// Clears the map, removing all key-value pairs.
Expand Down
2 changes: 1 addition & 1 deletion src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl<S: VecStorage<u8> + ?Sized> StringInner<S> {
/// ```
#[inline]
pub fn capacity(&self) -> usize {
self.vec.storage_capacity()
self.vec.capacity()
}

/// Appends the given [`char`] to the end of this `String`.
Expand Down
17 changes: 5 additions & 12 deletions src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,6 @@ impl<T, const N: usize> Vec<T, N> {
{
self.as_mut_view().drain(range)
}

/// Returns the maximum number of elements the vector can hold.
///
/// This method is not available on a `VecView`, use [`storage_len`](VecInner::storage_capacity) instead
pub const fn capacity(&self) -> usize {
self.buffer.buffer.len()
}
}

impl<T> VecView<T> {
Expand Down Expand Up @@ -486,7 +479,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
}

/// Returns the maximum number of elements the vector can hold.
pub fn storage_capacity(&self) -> usize {
pub fn capacity(&self) -> usize {
self.buffer.borrow().len()
}

Expand Down Expand Up @@ -565,7 +558,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
///
/// Returns back the `item` if the vector is full.
pub fn push(&mut self, item: T) -> Result<(), T> {
if self.len < self.storage_capacity() {
if self.len < self.capacity() {
unsafe { self.push_unchecked(item) }
Ok(())
} else {
Expand Down Expand Up @@ -639,7 +632,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
where
T: Clone,
{
if new_len > self.storage_capacity() {
if new_len > self.capacity() {
return Err(());
}

Expand Down Expand Up @@ -759,7 +752,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {
/// Normally, here, one would use [`clear`] instead to correctly drop
/// the contents and thus not leak memory.
pub unsafe fn set_len(&mut self, new_len: usize) {
debug_assert!(new_len <= self.storage_capacity());
debug_assert!(new_len <= self.capacity());

self.len = new_len
}
Expand Down Expand Up @@ -835,7 +828,7 @@ impl<T, S: VecStorage<T> + ?Sized> VecInner<T, S> {

/// Returns true if the vec is full
pub fn is_full(&self) -> bool {
self.len == self.storage_capacity()
self.len == self.capacity()
}

/// Returns true if the vec is empty
Expand Down