Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RefCell::try_borrow_unguarded #59211

Merged
merged 4 commits into from
Apr 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tweak documentation of RefCell::borrow_state
  • Loading branch information
nox committed Mar 16, 2019
commit a9388c28c2a6cfb82724612b4d3601475dee9325
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