about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-03 21:46:47 +0000
committerbors <bors@rust-lang.org>2014-07-03 21:46:47 +0000
commit5d5c20647f45f2eb74f337e5434bbe63b0c43345 (patch)
tree155aab01cbadfe647f739c31ce46b29b792ea7ae /src/libcollections
parentdd812ccbb56193c36819993dea25912788b447f0 (diff)
parent9bd6479912990046947913f160f69bc550dd3817 (diff)
downloadrust-5d5c20647f45f2eb74f337e5434bbe63b0c43345.tar.gz
rust-5d5c20647f45f2eb74f337e5434bbe63b0c43345.zip
auto merge of #15377 : alexcrichton/rust/rollup, r=alexcrichton
Closes #15276 (Guide: if)
Closes #15280 (std::os - Add join_paths, make setenv non-utf8 capable)
Closes #15314 (Guide: functions)
Closes #15327 (Simplify PatIdent to contain an Ident rather than a Path)
Closes #15340 (Guide: add mutable binding section)
Closes #15342 (Fix ICE with nested macro_rules!-style macros)
Closes #15350 (Remove duplicated slash in install script path)
Closes #15351 (correct a few spelling mistakes in the tutorial)
Closes #15352 (librustc: Have the kind checker check sub-bounds in trait casts.)
Closes #15359 (Fix spelling errors.)
Closes #15361 (Rename set_broadast() to set_broadcast().)
Closes #15366 (Simplify creating a parser from a token tree)
Closes #15367 (Add examples for StrVector methods)
Closes #15372 (Vec::grow should use reserve_additional, Vec::reserve should check against capacity)
Closes #15373 (Fix minor issues in the documentation of libtime.)
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/str.rs20
-rw-r--r--src/libcollections/vec.rs5
2 files changed, 21 insertions, 4 deletions
diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs
index fd8ce11d0b5..ddba4b34e3a 100644
--- a/src/libcollections/str.rs
+++ b/src/libcollections/str.rs
@@ -160,9 +160,27 @@ pub fn from_chars(chs: &[char]) -> String {
 /// Methods for vectors of strings
 pub trait StrVector {
     /// Concatenate a vector of strings.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// let first = "Restaurant at the End of the".to_string();
+    /// let second = " Universe".to_string();
+    /// let string_vec = vec![first, second];
+    /// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".to_string());
+    /// ```
     fn concat(&self) -> String;
 
     /// Concatenate a vector of strings, placing a given separator between each.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// let first = "Roast".to_string();
+    /// let second = "Sirloin Steak".to_string();
+    /// let string_vec = vec![first, second];
+    /// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".to_string());
+    /// ```
     fn connect(&self, sep: &str) -> String;
 }
 
@@ -172,7 +190,7 @@ impl<'a, S: Str> StrVector for &'a [S] {
             return String::new();
         }
 
-        // `len` calculation may overflow but push_str but will check boundaries
+        // `len` calculation may overflow but push_str will check boundaries
         let len = self.iter().map(|s| s.as_slice().len()).sum();
 
         let mut result = String::with_capacity(len);
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index 2ffc168f82c..d53ecabd5a9 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -253,8 +253,7 @@ impl<T: Clone> Vec<T> {
     /// assert_eq!(vec, vec!("hello", "world", "world"));
     /// ```
     pub fn grow(&mut self, n: uint, value: &T) {
-        let new_len = self.len() + n;
-        self.reserve(new_len);
+        self.reserve_additional(n);
         let mut i: uint = 0u;
 
         while i < n {
@@ -497,7 +496,7 @@ impl<T> Vec<T> {
     /// assert!(vec.capacity() >= 10);
     /// ```
     pub fn reserve(&mut self, capacity: uint) {
-        if capacity >= self.len {
+        if capacity > self.cap {
             self.reserve_exact(num::next_power_of_two(capacity))
         }
     }