Skip to content

Explain how Vec::with_capacity is faithful#99790

Closed
workingjubilee wants to merge 1 commit intorust-lang:masterfrom
workingjubilee:explain-vec-with-cap
Closed

Explain how Vec::with_capacity is faithful#99790
workingjubilee wants to merge 1 commit intorust-lang:masterfrom
workingjubilee:explain-vec-with-cap

Conversation

@workingjubilee
Copy link
Copy Markdown
Member

@workingjubilee workingjubilee commented Jul 27, 2022

There are concerns that the doc changes in 95dc353
are breaking changes in the promised API. In this commit, I explain in more detail
the exact promise that Vec::with_capacity is really making:
Vec is trying to act unsurprising by relaying information faithfully to the allocator,
it is not committing to internal details of Vec itself beyond that.
As it happens, we don't get useful capacity information from allocators,
but once upon a time Rust did capacity recalculation from available data,
and we should reserve the right to do so again if it seems profitable and correct.

This path avoids adding a duplicate with_capacity_exact to Vec's already-formidable API surface.

closes #99385.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removal of exact capacity guarantee for Vec::with_capacity() is a breaking change