about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorJason Thompson <jason@jthompson.ca>2014-07-03 06:02:21 -0400
committerAlex Crichton <alex@alexcrichton.com>2014-07-03 12:54:52 -0700
commit7db691e010c34d156ff31eda2db0560738c45837 (patch)
tree56035a66afb55b6e1890532003cba961fd67f49a /src/libcollections
parent2f355b79ddb49c45fb3396352f464458ad867234 (diff)
downloadrust-7db691e010c34d156ff31eda2db0560738c45837.tar.gz
rust-7db691e010c34d156ff31eda2db0560738c45837.zip
Add examples for StrVector methods
- examples for connect and concat
- also fixed extra word in existing docs
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/str.rs20
1 files changed, 19 insertions, 1 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);