From: Corey Farwell Date: Sat, 3 Jun 2017 18:40:23 +0000 (-0400) Subject: Improve doc examples for `Cow::into_owned`. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=6f3919d886258327e30c7a4630e70e56ddf924a1;p=rust.git Improve doc examples for `Cow::into_owned`. --- 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 @@ pub fn to_mut(&mut self) -> &mut ::Owned { /// /// # 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 = 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) -> ::Owned {