Shrinks the capacity of the vector as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.
As I read this, “it” refers to “the capacity of the vector,” and thus the rest of the sentence is saying that
vec.capacity() >= vec.len(). This should be rephrased so that it is clearly talking about the size of the backing allocation.
The language of
reserve_exact is also misleading:
Reserves the minimum capacity for exactly
additional more elements to be inserted in the given
Vec<T>. After calling
reserve_exact , capacity will be greater than or equal to
self.len() + additional. Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore capacity can not be relied upon to be precisely minimal. Prefer
reserve if future insertions are expected.
This one says that the
cap field of the vector may not be equal to
len, which is indeed a fair statement after reviewing the implementation. But the second paragraph seems to be implying that this is due to the will of the allocator; that is not the case here! (the cases where
cap > requested on exit are simply the cases where
cap > requested on entry!)