Rollup merge of #121213 - Takashiidobe:takashi/example-for-rc-into-inner, 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.
This commit is contained in:
Matthias Krüger 2024-03-05 06:40:29 +01:00 committed by GitHub
commit c2f6c0b806
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -944,6 +944,21 @@ pub fn try_unwrap(this: Self) -> Result<T, Self> {
/// 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> {