Skip to content

Commit

Permalink
Improve doc examples for Cow::into_owned.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Jun 3, 2017
1 parent 4225019 commit 6f3919d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/libcollections/borrow.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 6f3919d

Please sign in to comment.