- /// Upgrades a weak reference to a strong reference.
- ///
- /// Upgrades the `Weak<T>` reference to an `Rc<T>`, if possible.
- ///
- /// Returns `None` if there were no strong references and the data was destroyed.
- ///
- /// # Examples
- ///
- /// ```
- /// use std::rc::Rc;
- ///
- /// let five = Rc::new(5i);
- ///
- /// let weak_five = five.downgrade();
- ///
- /// let strong_five: Option<Rc<_>> = weak_five.upgrade();
- /// ```
- #[cfg(stage0)] // NOTE remove after next snapshot
- pub fn upgrade(&self) -> Option<Rc<T>> {
- if self.strong() == 0 {
- None
- } else {
- self.inc_strong();
- Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync })
- }
- }