Skip to content

Commit

Permalink
Auto merge of #42414 - frewsxcv:frewsxcv/improve-cow-docs, r=QuietMis…
Browse files Browse the repository at this point in the history
…dreavus

Improve `Cow` method doc examples.

None
  • Loading branch information
bors committed Jun 5, 2017
2 parents 13eb0ec + 07cae10 commit d015610
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/libcollections/borrow.rs
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit d015610

Please sign in to comment.