diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-06-03 14:40:23 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2017-06-03 14:40:23 -0400 |
| commit | 6f3919d886258327e30c7a4630e70e56ddf924a1 (patch) | |
| tree | e07646f44fc30a434a8743880fb0d2e1a8e29d28 | |
| parent | 4225019750f437c8c247a2682f01abe5ada69c46 (diff) | |
| download | rust-6f3919d886258327e30c7a4630e70e56ddf924a1.tar.gz rust-6f3919d886258327e30c7a4630e70e56ddf924a1.zip | |
Improve doc examples for `Cow::into_owned`.
| -rw-r--r-- | src/libcollections/borrow.rs | 25 |
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 { |
