1
Fork 0

Update docstring for truncate

This documentation confused me when trying to use truncate on a project. Originally, it was unclear whether truncate removed the last `len` elements, or whether it cut down the vector to be exactly `len` elements long. The example was also ambiguous.
This commit is contained in:
Cameron Sun 2015-10-28 21:38:46 -04:00
parent 8ca0acc25a
commit 39289d00fd

View file

@ -429,7 +429,7 @@ impl<T> Vec<T> {
} }
} }
/// Shorten a vector, dropping excess elements. /// Shorten a vector to be `len` elements long, dropping excess elements.
/// ///
/// If `len` is greater than the vector's current length, this has no /// If `len` is greater than the vector's current length, this has no
/// effect. /// effect.
@ -437,7 +437,7 @@ impl<T> Vec<T> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// let mut vec = vec![1, 2, 3, 4]; /// let mut vec = vec![1, 2, 3, 4, 5];
/// vec.truncate(2); /// vec.truncate(2);
/// assert_eq!(vec, [1, 2]); /// assert_eq!(vec, [1, 2]);
/// ``` /// ```