Skip to content

Commit

Permalink
add example for Rc::would_unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-piziak committed Aug 21, 2016
1 parent 7ac11ca commit 5310d11
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/liballoc/rc.rs
Expand Up @@ -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")]
Expand Down

0 comments on commit 5310d11

Please sign in to comment.