@@ -191,13 +191,16 @@ impl<'a, B: ?Sized> Cow<'a, B>
191
191
/// # Examples
192
192
///
193
193
/// ```
194
+ /// use std::ascii::AsciiExt;
194
195
/// use std::borrow::Cow;
195
196
///
196
- /// let mut cow: Cow<[_]> = Cow::Owned(vec![1, 2, 3]);
197
+ /// let mut cow = Cow::Borrowed("foo");
198
+ /// cow.to_mut().make_ascii_uppercase();
197
199
///
198
- /// let hello = cow.to_mut();
199
- ///
200
- /// assert_eq!(hello, &[1, 2, 3]);
200
+ /// assert_eq!(
201
+ /// cow,
202
+ /// Cow::Owned(String::from("FOO")) as Cow<str>
203
+ /// );
201
204
/// ```
202
205
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
203
206
pub fn to_mut ( & mut self ) -> & mut <B as ToOwned >:: Owned {
@@ -219,14 +222,33 @@ impl<'a, B: ?Sized> Cow<'a, B>
219
222
///
220
223
/// # Examples
221
224
///
225
+ /// Calling `into_owned` on a `Cow::Borrowed` clones the underlying data
226
+ /// and becomes a `Cow::Owned`:
227
+ ///
222
228
/// ```
223
229
/// use std::borrow::Cow;
224
230
///
225
- /// let cow: Cow<[_]> = Cow::Owned(vec![1, 2, 3]);
231
+ /// let s = "Hello world!";
232
+ /// let cow = Cow::Borrowed(s);
233
+ ///
234
+ /// assert_eq!(
235
+ /// cow.into_owned(),
236
+ /// Cow::Owned(String::from(s))
237
+ /// );
238
+ /// ```
239
+ ///
240
+ /// Calling `into_owned` on a `Cow::Owned` is a no-op:
241
+ ///
242
+ /// ```
243
+ /// use std::borrow::Cow;
226
244
///
227
- /// let hello = cow.into_owned();
245
+ /// let s = "Hello world!";
246
+ /// let cow: Cow<str> = Cow::Owned(String::from(s));
228
247
///
229
- /// assert_eq!(vec![1, 2, 3], hello);
248
+ /// assert_eq!(
249
+ /// cow.into_owned(),
250
+ /// Cow::Owned(String::from(s))
251
+ /// );
230
252
/// ```
231
253
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
232
254
pub fn into_owned ( self ) -> <B as ToOwned >:: Owned {
0 commit comments