From 5310d1110dd245ff4e12cd7b483bec53640bf58b Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Sun, 21 Aug 2016 17:18:21 -0400 Subject: [PATCH] add example for `Rc::would_unwrap` Part of #29372 r? @steveklabnik --- src/liballoc/rc.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 2beb652aa017a..3a158240c3a26 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -263,6 +263,23 @@ impl Rc { } /// 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")]