Skip to content

Commit ab938b9

Browse files
committed
Improve documentation for [A]Rc::into_inner
General improvements, and also aims to better encourage the reader to actually check out Arc::try_unwrap.
1 parent d6b151f commit ab938b9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Diff for: library/alloc/src/rc.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,11 @@ impl<T, A: Allocator> Rc<T, A> {
938938
/// it is guaranteed that exactly one of the calls returns the inner value.
939939
/// This means in particular that the inner value is not dropped.
940940
///
941-
/// This is equivalent to `Rc::try_unwrap(this).ok()`. (Note that these are not equivalent for
942-
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`.)
941+
/// [`Rc::try_unwrap`] is conceptually similar to `Rc::into_inner`.
942+
/// And while they are meant for different use-cases, `Rc::into_inner(this)`
943+
/// is in fact equivalent to <code>[Rc::try_unwrap]\(this).[ok][Result::ok]()</code>.
944+
/// (Note that the same kind of equivalence does **not** hold true for
945+
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`!)
943946
#[inline]
944947
#[stable(feature = "rc_into_inner", since = "1.70.0")]
945948
pub fn into_inner(this: Self) -> Option<T> {

Diff for: library/alloc/src/sync.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,13 @@ impl<T, A: Allocator> Arc<T, A> {
983983
/// it is guaranteed that exactly one of the calls returns the inner value.
984984
/// This means in particular that the inner value is not dropped.
985985
///
986-
/// The similar expression `Arc::try_unwrap(this).ok()` does not
987-
/// offer such a guarantee. See the last example below
988-
/// and the documentation of [`Arc::try_unwrap`].
986+
/// [`Arc::try_unwrap`] is conceptually similar to `Arc::into_inner`, but it
987+
/// is meant for different use-cases. If used as a direct replacement
988+
/// for `Arc::into_inner` anyway, such as with the expression
989+
/// <code>[Arc::try_unwrap]\(this).[ok][Result::ok]()</code>, then it does
990+
/// **not** give the same guarantee as described in the previous paragraph.
991+
/// For more information, see the examples below and read the documentation
992+
/// of [`Arc::try_unwrap`].
989993
///
990994
/// # Examples
991995
///

0 commit comments

Comments
 (0)