about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Turner <jonathandturner@users.noreply.github.com>2016-08-22 15:34:22 -0700
committerGitHub <noreply@github.com>2016-08-22 15:34:22 -0700
commit375695c956a32f4056a9622697f3f421fb3b55e0 (patch)
treeb358b9adc87c98e8cbbc9ffa12d563bbc05aa8d9
parentb560f5a7bc66d813138d4a4272318809709c9b8f (diff)
parent5310d1110dd245ff4e12cd7b483bec53640bf58b (diff)
downloadrust-375695c956a32f4056a9622697f3f421fb3b55e0.tar.gz
rust-375695c956a32f4056a9622697f3f421fb3b55e0.zip
Rollup merge of #35881 - matthew-piziak:rc-would-unwrap-example, r=GuillaumeGomez
add example for `Rc::would_unwrap`

Part of #29372

r? @steveklabnik
-rw-r--r--src/liballoc/rc.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 2beb652aa01..3a158240c3a 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -263,6 +263,23 @@ impl<T> Rc<T> {
     }
 
     /// Checks if `Rc::try_unwrap` would return `Ok`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(rc_would_unwrap)]
+    ///
+    /// use std::rc::Rc;
+    ///
+    /// let x = Rc::new(3);
+    /// assert!(Rc::would_unwrap(&x));
+    /// assert_eq!(Rc::try_unwrap(x), Ok(3));
+    ///
+    /// let x = Rc::new(4);
+    /// let _y = x.clone();
+    /// assert!(!Rc::would_unwrap(&x));
+    /// assert_eq!(Rc::try_unwrap(x), Err(Rc::new(4)));
+    /// ```
     #[unstable(feature = "rc_would_unwrap",
                reason = "just added for niche usecase",
                issue = "28356")]