Clarify docs of RefCell
Comparison operators only panic if the `RefCell` is mutably borrowed, and `RefCell::swap()` can also panic if swapping a `RefCell` with itself.
This commit is contained in:
parent
822f8c22f5
commit
d2eb2bb854
@ -807,7 +807,8 @@ pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T {
|
|||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently borrowed, or
|
||||||
|
/// if `self` and `other` point to the same `RefCell`.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
@ -1193,7 +1194,7 @@ fn default() -> RefCell<T> {
|
|||||||
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
|
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &RefCell<T>) -> bool {
|
fn eq(&self, other: &RefCell<T>) -> bool {
|
||||||
*self.borrow() == *other.borrow()
|
*self.borrow() == *other.borrow()
|
||||||
@ -1207,7 +1208,7 @@ impl<T: ?Sized + Eq> Eq for RefCell<T> {}
|
|||||||
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
|
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
|
||||||
self.borrow().partial_cmp(&*other.borrow())
|
self.borrow().partial_cmp(&*other.borrow())
|
||||||
@ -1215,7 +1216,7 @@ fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
|
|||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn lt(&self, other: &RefCell<T>) -> bool {
|
fn lt(&self, other: &RefCell<T>) -> bool {
|
||||||
*self.borrow() < *other.borrow()
|
*self.borrow() < *other.borrow()
|
||||||
@ -1223,7 +1224,7 @@ fn lt(&self, other: &RefCell<T>) -> bool {
|
|||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn le(&self, other: &RefCell<T>) -> bool {
|
fn le(&self, other: &RefCell<T>) -> bool {
|
||||||
*self.borrow() <= *other.borrow()
|
*self.borrow() <= *other.borrow()
|
||||||
@ -1231,7 +1232,7 @@ fn le(&self, other: &RefCell<T>) -> bool {
|
|||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn gt(&self, other: &RefCell<T>) -> bool {
|
fn gt(&self, other: &RefCell<T>) -> bool {
|
||||||
*self.borrow() > *other.borrow()
|
*self.borrow() > *other.borrow()
|
||||||
@ -1239,7 +1240,7 @@ fn gt(&self, other: &RefCell<T>) -> bool {
|
|||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ge(&self, other: &RefCell<T>) -> bool {
|
fn ge(&self, other: &RefCell<T>) -> bool {
|
||||||
*self.borrow() >= *other.borrow()
|
*self.borrow() >= *other.borrow()
|
||||||
@ -1250,7 +1251,7 @@ fn ge(&self, other: &RefCell<T>) -> bool {
|
|||||||
impl<T: ?Sized + Ord> Ord for RefCell<T> {
|
impl<T: ?Sized + Ord> Ord for RefCell<T> {
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// Panics if the value in either `RefCell` is currently borrowed.
|
/// Panics if the value in either `RefCell` is currently mutably borrowed.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self, other: &RefCell<T>) -> Ordering {
|
fn cmp(&self, other: &RefCell<T>) -> Ordering {
|
||||||
self.borrow().cmp(&*other.borrow())
|
self.borrow().cmp(&*other.borrow())
|
||||||
|
Loading…
Reference in New Issue
Block a user