Skip to content

Improved examples on Vec documentation #18254

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
Oct 28, 2014
Merged
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
10 changes: 8 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,18 @@ impl<T> Vec<T> {
}
}

/// Shrinks the capacity of the vector as much as possible.
/// 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.
///
/// # Example
///
/// ```
/// let mut vec = vec![1i, 2, 3];
/// let mut vec: Vec<int> = Vec::with_capacity(10);
/// vec.push_all([1, 2, 3]);
/// assert_eq!(vec.capacity(), 10);
/// vec.shrink_to_fit();
/// assert!(vec.capacity() >= 3);
/// ```
#[stable]
pub fn shrink_to_fit(&mut self) {
Expand Down Expand Up @@ -830,6 +835,7 @@ impl<T> Vec<T> {
/// for num in vec.iter_mut() {
/// *num = 0;
/// }
/// assert_eq!(vec, vec![0i, 0, 0]);
/// ```
#[inline]
pub fn iter_mut<'a>(&'a mut self) -> MutItems<'a,T> {
Expand Down