Skip to content

Commit

Permalink
Tweak documentation of RefCell::borrow_state
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Mar 16, 2019
1 parent fab71dd commit a9388c2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,14 @@ impl<T> RefCell<T> {
}

impl<T: ?Sized> RefCell<T> {
/// Query the current state of this `RefCell`
/// Queries the current state of this `RefCell`.
///
/// The returned value can be dispatched on to determine if a call to
/// `borrow` or `borrow_mut` would succeed.
/// A return value of `BorrowState::Writing` signals that this `RefCell`
/// is currently mutably borrowed, while `BorrowState::Reading` signals
/// that it is immutably borrowed.
///
/// This is mostly useful in rare use cases with `RefCell::as_ptr` to
/// access the data without changing its borrow state, use with care.
///
/// # Examples
///
Expand All @@ -780,9 +784,9 @@ impl<T: ?Sized> RefCell<T> {
/// let c = RefCell::new(5);
///
/// match c.borrow_state() {
/// BorrowState::Writing => println!("Cannot be borrowed"),
/// BorrowState::Reading => println!("Cannot be borrowed mutably"),
/// BorrowState::Unused => println!("Can be borrowed (mutably as well)"),
/// BorrowState::Writing => println!("currently borrowed mutably"),
/// BorrowState::Reading => println!("currently borrowed immutably"),
/// BorrowState::Unused => println!("not borrowed"),
/// }
/// ```
#[unstable(feature = "borrow_state", issue = "27733")]
Expand Down

0 comments on commit a9388c2

Please sign in to comment.