File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -160,9 +160,27 @@ pub fn from_chars(chs: &[char]) -> String {
160
160
/// Methods for vectors of strings
161
161
pub trait StrVector {
162
162
/// Concatenate a vector of strings.
163
+ ///
164
+ /// # Example
165
+ ///
166
+ /// ```rust
167
+ /// let first = "Restaurant at the End of the".to_string();
168
+ /// let second = " Universe".to_string();
169
+ /// let string_vec = vec![first, second];
170
+ /// assert_eq!(string_vec.concat(), "Restaurant at the End of the Universe".to_string());
171
+ /// ```
163
172
fn concat ( & self ) -> String ;
164
173
165
174
/// Concatenate a vector of strings, placing a given separator between each.
175
+ ///
176
+ /// # Example
177
+ ///
178
+ /// ```rust
179
+ /// let first = "Roast".to_string();
180
+ /// let second = "Sirloin Steak".to_string();
181
+ /// let string_vec = vec![first, second];
182
+ /// assert_eq!(string_vec.connect(", "), "Roast, Sirloin Steak".to_string());
183
+ /// ```
166
184
fn connect ( & self , sep : & str ) -> String ;
167
185
}
168
186
@@ -172,7 +190,7 @@ impl<'a, S: Str> StrVector for &'a [S] {
172
190
return String :: new ( ) ;
173
191
}
174
192
175
- // `len` calculation may overflow but push_str but will check boundaries
193
+ // `len` calculation may overflow but push_str will check boundaries
176
194
let len = self . iter ( ) . map ( |s| s. as_slice ( ) . len ( ) ) . sum ( ) ;
177
195
178
196
let mut result = String :: with_capacity ( len) ;
You can’t perform that action at this time.
0 commit comments