diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-05 06:40:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 06:40:29 +0100 |
| commit | c2f6c0b8062c3903e1ade11179f5a0c4256d2e00 (patch) | |
| tree | 8aab8fb4278d40015b04092b2ac0410dba5d9ed2 /library/alloc | |
| parent | 1547c076bfec8abb819d6a81e1e4095d267bd5b4 (diff) | |
| parent | 1f2db3ddfcc1af86221bcffbcbc0ac789cabe89b (diff) | |
| download | rust-c2f6c0b8062c3903e1ade11179f5a0c4256d2e00.tar.gz rust-c2f6c0b8062c3903e1ade11179f5a0c4256d2e00.zip | |
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.
Diffstat (limited to 'library/alloc')
| -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 084157b97ab..981f487872c 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> { |
