pub struct MLRefCell<T: ?Sized> { /* private fields */ }
Expand description
A RefCell which can be “locked” to prevent future mutable borrows
Implementations
sourceimpl<T> MLRefCell<T>
impl<T> MLRefCell<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the MLRefCell
, returning the wrapped value
sourcepub fn replace(&self, val: T) -> T
pub fn replace(&self, val: T) -> T
Replaces the wrapped value with a new one, returning the old value, without deinitializing either one.
This function corresponds to std::mem::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
Replaces the wrapped value with a new one computed from f, returning the old value, without deinitializing either one.
sourceimpl<T: ?Sized> MLRefCell<T>
impl<T: ?Sized> MLRefCell<T>
sourcepub fn lock(&self) -> Result<(), AlreadyLockedError>
pub fn lock(&self) -> Result<(), AlreadyLockedError>
Locks the MLRefCell
, so that future mutable borrows will result in an error.
sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Immutably borrows the wrapped value, panicking if the value is currently mutably borrowed.
sourcepub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
pub fn try_borrow(&self) -> Result<Ref<'_, T>, BorrowError>
Immutably borrows the wrapped value, returning a BorrowError
if the value is currently
mutably borrowed.
sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Mutably borrows the wrapped value, panicking if the value is either currently borrowed or
if the MLRefCell
is locked.
sourcepub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
pub fn try_borrow_mut(&self) -> Result<RefMut<'_, T>, BorrowMutError>
Mutably borrows the wrapped value, returning an error if the value is either currently borrowed or
if the MLRefCell
is locked.
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
This call borrows self
mutably, so there is no need for runtime checks (including lock
checks). This method is
usually not what you want, so use borrow_mut
instead.
sourcepub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
pub unsafe fn try_borrow_unguarded(&self) -> Result<&T, BorrowError>
Immutably borrows the wrapped value, returning an error if the value is currently mutably borrowed.
Unlike RefCell::borrow
, this method is unsafe because it does not return a Ref
, thus leaving the borrow flag untouched. Mutably borrowing the RefCell
while the reference returned by this method is alive is undefined behaviour.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for MLRefCell<T>
impl<T: ?Sized> Send for MLRefCell<T> where
T: Send,
impl<T> !Sync for MLRefCell<T>
impl<T: ?Sized> Unpin for MLRefCell<T> where
T: Unpin,
impl<T: ?Sized> UnwindSafe for MLRefCell<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more