diff options
| author | Takashiidobe <idobetakashi@gmail.com> | 2024-02-16 20:21:34 -0500 |
|---|---|---|
| committer | Takashiidobe <idobetakashi@gmail.com> | 2024-02-16 20:21:34 -0500 |
| commit | 1f2db3ddfcc1af86221bcffbcbc0ac789cabe89b (patch) | |
| tree | 17d47333719c1bda16abcabcaf1ddce730b85c6c /library/alloc/src | |
| parent | bccb9bbb418a30aeb332052e721beb6ebc6b1ce7 (diff) | |
| download | rust-1f2db3ddfcc1af86221bcffbcbc0ac789cabe89b.tar.gz rust-1f2db3ddfcc1af86221bcffbcbc0ac789cabe89b.zip | |
Add an example to demonstrate how Rc::into_inner works
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/rc.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 2cc38d90ffe..5c408f573bf 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -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> { |
