pub struct BetterRefCell<T: ?Sized> { /* private fields */ }Expand description
An enhanced RefCell with double-borrowing support.
Implementations§
Source§impl<T> BetterRefCell<T>
impl<T> BetterRefCell<T>
Sourcepub const fn new(value: T) -> Self
pub const fn new(value: T) -> Self
Equivalent to RefCell::new.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Equivalent to RefCell::into_inner.
Sourcepub fn replace(&self, t: T) -> T
pub fn replace(&self, t: T) -> T
Equivalent to RefCell::replace.
Sourcepub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T
pub fn replace_with<F: FnOnce(&mut T) -> T>(&self, f: F) -> T
Equivalent to RefCell::replace_with.
Sourcepub fn swap(&self, other: &Self)
pub fn swap(&self, other: &Self)
Equivalent to RefCell::swap.
Source§impl<T: ?Sized> BetterRefCell<T>
impl<T: ?Sized> BetterRefCell<T>
Sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Equivalent to RefCell::borrow.
Sourcepub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
Equivalent to RefCell::try_borrow.
Sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Equivalent to RefCell::borrow_mut.
Sourcepub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
Equivalent to RefCell::try_borrow_mut.
Sourcepub fn as_ptr(&self) -> *mut T
pub fn as_ptr(&self) -> *mut T
Equivalent to RefCell::as_ptr.
Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Equivalent to RefCell::get_mut.
Sourcepub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
pub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
Equivalent to RefCell::try_borrow_unguarded.
Source§impl<T: Default> BetterRefCell<T>
impl<T: Default> BetterRefCell<T>
Sourcepub fn take(&self) -> T
pub fn take(&self) -> T
Equivalent to RefCell::take.
Source§impl<T: ?Sized> BetterRefCell<T>
impl<T: ?Sized> BetterRefCell<T>
Sourcepub fn unborrow<R>(&self, borrowed: &mut T, f: impl FnOnce() -> R) -> R
pub fn unborrow<R>(&self, borrowed: &mut T, f: impl FnOnce() -> R) -> R
Temporarily re-grant exclusive access to the internal value, allowing borrow_mut/try_borrow_mut again in f.
§Panics
This function panics only if any of the following conditions are violated:
borrowedmust point to the internal value stored inself.- All borrow guards obtained from
selfwithinfmust be dropped beforefreturns.
Sourcepub unsafe fn unborrow_unchecked<R>(
&self,
borrowed: &mut T,
f: impl FnOnce() -> R,
) -> R
pub unsafe fn unborrow_unchecked<R>( &self, borrowed: &mut T, f: impl FnOnce() -> R, ) -> R
Temporarily re-grant exclusive access to the internal value, allowing borrow_mut/try_borrow_mut again in f.
§Safety
This function is safe to call if all of the following conditions are met:
borrowedmust point to the internal value stored inself.- All borrow guards obtained from
selfwithinfmust be dropped beforefreturns. - Any borrow guards obtained from
selfoutside offmust not be used withinf.
Sourcepub fn unborrow_ref<R>(&self, borrowed: &T, f: impl FnOnce() -> R) -> R
pub fn unborrow_ref<R>(&self, borrowed: &T, f: impl FnOnce() -> R) -> R
Temporarily re-grant shared access to the internal value, allowing borrow/try_borrow again in f.
§Panics
This function panics only if any of the following conditions are violated:
borrowedmust point to the internal value stored inself.- If
borrowedis (transitively) originated fromRefMut, then allRefs obtained fromselfwithinfmust be dropped beforefreturns.
Sourcepub unsafe fn unborrow_ref_unchecked<R>(
&self,
borrowed: &T,
f: impl FnOnce() -> R,
) -> R
pub unsafe fn unborrow_ref_unchecked<R>( &self, borrowed: &T, f: impl FnOnce() -> R, ) -> R
Temporarily re-grant shared access to the internal value, allowing borrow/try_borrow again in f.
§Safety
This function is safe to call if all of the following conditions are met:
borrowedmust point to the internal value stored inself.- If
borrowedis (transitively) originated fromRefMut, then allRefs obtained fromselfwithinfmust be dropped beforefreturns. - Any borrow guards obtained from
selfoutside offmust not be used withinf.
Trait Implementations§
Source§impl<T: Clone> Clone for BetterRefCell<T>
impl<T: Clone> Clone for BetterRefCell<T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Equivalent to RefCell::clone.
Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Equivalent to RefCell::clone_from.
Source§impl<T: Default> Default for BetterRefCell<T>
impl<T: Default> Default for BetterRefCell<T>
Source§fn default() -> Self
fn default() -> Self
Equivalent to RefCell::default.
Source§impl<T> From<T> for BetterRefCell<T>
impl<T> From<T> for BetterRefCell<T>
Source§fn from(t: T) -> Self
fn from(t: T) -> Self
Equivalent to RefCell::from.
Source§impl<T: ?Sized + Ord> Ord for BetterRefCell<T>
impl<T: ?Sized + Ord> Ord for BetterRefCell<T>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Equivalent to RefCell::cmp.
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: ?Sized + PartialOrd> PartialOrd for BetterRefCell<T>
impl<T: ?Sized + PartialOrd> PartialOrd for BetterRefCell<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Equivalent to RefCell::partial_cmp.
Source§fn lt(&self, other: &Self) -> bool
fn lt(&self, other: &Self) -> bool
Equivalent to RefCell::lt.
Source§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
Equivalent to RefCell::le.
Source§fn gt(&self, other: &Self) -> bool
fn gt(&self, other: &Self) -> bool
Equivalent to RefCell::gt.
Source§fn ge(&self, other: &Self) -> bool
fn ge(&self, other: &Self) -> bool
Equivalent to RefCell::ge.