about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-06-03 14:40:23 -0400
committerCorey Farwell <coreyf@rwell.org>2017-06-03 14:40:23 -0400
commit6f3919d886258327e30c7a4630e70e56ddf924a1 (patch)
treee07646f44fc30a434a8743880fb0d2e1a8e29d28
parent4225019750f437c8c247a2682f01abe5ada69c46 (diff)
downloadrust-6f3919d886258327e30c7a4630e70e56ddf924a1.tar.gz
rust-6f3919d886258327e30c7a4630e70e56ddf924a1.zip
Improve doc examples for `Cow::into_owned`.
-rw-r--r--src/libcollections/borrow.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs
index 0de52b6696f..a889b635e87 100644
--- a/src/libcollections/borrow.rs
+++ b/src/libcollections/borrow.rs
@@ -219,14 +219,33 @@ impl<'a, B: ?Sized> Cow<'a, B>
     ///
     /// # Examples
     ///
+    /// Calling `into_owned` on a `Cow::Borrowed` clones the underlying data
+    /// and becomes a `Cow::Owned`:
+    ///
     /// ```
     /// use std::borrow::Cow;
     ///
-    /// let cow: Cow<[_]> = Cow::Owned(vec![1, 2, 3]);
+    /// let s = "Hello world!";
+    /// let cow = Cow::Borrowed(s);
+    ///
+    /// assert_eq!(
+    ///   cow.into_owned(),
+    ///   Cow::Owned(String::from(s))
+    /// );
+    /// ```
+    ///
+    /// Calling `into_owned` on a `Cow::Owned` is a no-op:
+    ///
+    /// ```
+    /// use std::borrow::Cow;
     ///
-    /// let hello = cow.into_owned();
+    /// let s = "Hello world!";
+    /// let cow: Cow<str> = Cow::Owned(String::from(s));
     ///
-    /// assert_eq!(vec![1, 2, 3], hello);
+    /// assert_eq!(
+    ///   cow.into_owned(),
+    ///   Cow::Owned(String::from(s))
+    /// );
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn into_owned(self) -> <B as ToOwned>::Owned {