about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMatthew Piziak <matthew.piziak@gmail.com>2016-08-21 17:18:21 -0400
committerMatthew Piziak <matthew.piziak@gmail.com>2016-08-21 17:18:52 -0400
commit5310d1110dd245ff4e12cd7b483bec53640bf58b (patch)
treef6868b326af5da73c0618d8631ed33453a75886a /src/liballoc
parent7ac11cad3fe85163dd8b0ca1f63af492509f9bfe (diff)
downloadrust-5310d1110dd245ff4e12cd7b483bec53640bf58b.tar.gz
rust-5310d1110dd245ff4e12cd7b483bec53640bf58b.zip
add example for `Rc::would_unwrap`
Part of #29372

r? @steveklabnik
Diffstat (limited to 'src/liballoc')
-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")]