Skip to content

Commit

Permalink
Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-in…
Browse files Browse the repository at this point in the history
…ner, r=cuviper

Add an example to demonstrate how Rc::into_inner works

This PR adds an example to Rc::into_inner, since it didn't have one previously.
  • Loading branch information
matthiaskrgr authored Mar 5, 2024
2 parents 1547c07 + 1f2db3d commit c2f6c0b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,21 @@ impl<T, A: Allocator> Rc<T, A> {
/// is in fact equivalent to <code>[Rc::try_unwrap]\(this).[ok][Result::ok]()</code>.
/// (Note that the same kind of equivalence does **not** hold true for
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`!)
///
/// # Examples
///
/// ```
/// use std::rc::Rc;
///
/// let x = Rc::new(3);
/// assert_eq!(Rc::into_inner(x), Some(3));
///
/// let x = Rc::new(4);
/// let y = Rc::clone(&x);
///
/// assert_eq!(Rc::into_inner(y), None);
/// assert_eq!(Rc::into_inner(x), Some(4));
/// ```
#[inline]
#[stable(feature = "rc_into_inner", since = "1.70.0")]
pub fn into_inner(this: Self) -> Option<T> {
Expand Down

0 comments on commit c2f6c0b

Please sign in to comment.