Skip to content

Commit a9388c2

Browse files
committed
Tweak documentation of RefCell::borrow_state
1 parent fab71dd commit a9388c2

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/libcore/cell.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,14 @@ impl<T> RefCell<T> {
765765
}
766766

767767
impl<T: ?Sized> RefCell<T> {
768-
/// Query the current state of this `RefCell`
768+
/// Queries the current state of this `RefCell`.
769769
///
770-
/// The returned value can be dispatched on to determine if a call to
771-
/// `borrow` or `borrow_mut` would succeed.
770+
/// A return value of `BorrowState::Writing` signals that this `RefCell`
771+
/// is currently mutably borrowed, while `BorrowState::Reading` signals
772+
/// that it is immutably borrowed.
773+
///
774+
/// This is mostly useful in rare use cases with `RefCell::as_ptr` to
775+
/// access the data without changing its borrow state, use with care.
772776
///
773777
/// # Examples
774778
///
@@ -780,9 +784,9 @@ impl<T: ?Sized> RefCell<T> {
780784
/// let c = RefCell::new(5);
781785
///
782786
/// match c.borrow_state() {
783-
/// BorrowState::Writing => println!("Cannot be borrowed"),
784-
/// BorrowState::Reading => println!("Cannot be borrowed mutably"),
785-
/// BorrowState::Unused => println!("Can be borrowed (mutably as well)"),
787+
/// BorrowState::Writing => println!("currently borrowed mutably"),
788+
/// BorrowState::Reading => println!("currently borrowed immutably"),
789+
/// BorrowState::Unused => println!("not borrowed"),
786790
/// }
787791
/// ```
788792
#[unstable(feature = "borrow_state", issue = "27733")]

0 commit comments

Comments
 (0)