diff options
| author | bors <bors@rust-lang.org> | 2017-06-05 15:38:24 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-05 15:38:24 +0000 |
| commit | d015610db7b7d30f3c92d3272ce166397a81349e (patch) | |
| tree | fbcf0aa06c37d7cc3044ff8f6df951afab756ac6 /src | |
| parent | 13eb0ec9f17c89a3cb06a8f3ae627c076839fa52 (diff) | |
| parent | 07cae108cb54e2586a0a63b9f4172a64c17f26e2 (diff) | |
| download | rust-d015610db7b7d30f3c92d3272ce166397a81349e.tar.gz rust-d015610db7b7d30f3c92d3272ce166397a81349e.zip | |
Auto merge of #42414 - frewsxcv:frewsxcv/improve-cow-docs, r=QuietMisdreavus
Improve `Cow` method doc examples. None
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/borrow.rs | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/libcollections/borrow.rs b/src/libcollections/borrow.rs index 0de52b6696f..a662e4b1f4f 100644 --- a/src/libcollections/borrow.rs +++ b/src/libcollections/borrow.rs @@ -191,13 +191,16 @@ impl<'a, B: ?Sized> Cow<'a, B> /// # Examples /// /// ``` + /// use std::ascii::AsciiExt; /// use std::borrow::Cow; /// - /// let mut cow: Cow<[_]> = Cow::Owned(vec![1, 2, 3]); + /// let mut cow = Cow::Borrowed("foo"); + /// cow.to_mut().make_ascii_uppercase(); /// - /// let hello = cow.to_mut(); - /// - /// assert_eq!(hello, &[1, 2, 3]); + /// assert_eq!( + /// cow, + /// Cow::Owned(String::from("FOO")) as Cow<str> + /// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned { @@ -219,14 +222,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 { |
