diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-02-10 23:41:36 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-10 23:41:36 -0500 |
| commit | 15bec3dd637d03995d8b47859b691b81c7d5c2dc (patch) | |
| tree | f9d971ee78bd175834546ce9d896840ff5c390c6 | |
| parent | 92cf7aecb4c1e45c9b09620e09598a8cd5bb4837 (diff) | |
| parent | b3937ea862e15321e85537ac6bd63ad51099c23f (diff) | |
| download | rust-15bec3dd637d03995d8b47859b691b81c7d5c2dc.tar.gz rust-15bec3dd637d03995d8b47859b691b81c7d5c2dc.zip | |
Rollup merge of #39701 - sgrif:sg-vec-reserve-docs, r=alexcrichton
Explicitly mention that `Vec::reserve` is based on len not capacity I spent a good chunk of time tracking down a buffer overrun bug that resulted from me mistakenly thinking that `reserve` was based on the current capacity not the current length. It would be helpful if this were called out explicitly in the docs.
| -rw-r--r-- | src/libcollections/vec.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index dc0f33d9bc3..3873b3535a0 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -437,7 +437,9 @@ impl<T> Vec<T> { /// Reserves capacity for at least `additional` more elements to be inserted /// in the given `Vec<T>`. The collection may reserve more space to avoid - /// frequent reallocations. + /// frequent reallocations. After calling `reserve`, capacity will be + /// greater than or equal to `self.len() + additional`. Does nothing if + /// capacity is already sufficient. /// /// # Panics /// @@ -456,8 +458,9 @@ impl<T> Vec<T> { } /// Reserves the minimum capacity for exactly `additional` more elements to - /// be inserted in the given `Vec<T>`. Does nothing if the capacity is already - /// sufficient. + /// 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 |
