[−][src]Struct cell::RefMut
A wrapper type for a mutably borrowed value from a RefCell<T>
.
See the module-level documentation for more.
Methods
impl<'b, T: ?Sized> RefMut<'b, T>
[src]
pub fn map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> RefMut<'b, U> where
F: FnOnce(&mut T) -> &mut U,
[src]
F: FnOnce(&mut T) -> &mut U,
Make a new RefMut
for a component of the borrowed data, e.g. an enum
variant.
The RefCell
is already mutably borrowed, so this cannot fail.
This is an associated function that needs to be used as
RefMut::map(...)
. A method would interfere with methods of the same
name on the contents of a RefCell
used through Deref
.
Examples
use std::cell::{RefCell, RefMut}; let c = RefCell::new((5, 'b')); { let b1: RefMut<(u32, char)> = c.borrow_mut(); let mut b2: RefMut<u32> = RefMut::map(b1, |t| &mut t.0); assert_eq!(*b2, 5); *b2 = 42; } assert_eq!(*c.borrow(), (42, 'b'));
pub fn map_val<U: Sized, F>(orig: RefMut<'b, T>, f: F) -> RefValMut<'b, U> where
F: FnOnce(&'b mut T) -> U,
[src]
F: FnOnce(&'b mut T) -> U,
Make a new RefValMut
from the borrowed data.
The RefCell
is already immutably borrowed, so this operation
cannot fail.
Trait Implementations
impl<T: ?Sized + Debug, '_> Debug for RefMut<'_, T>
[src]
impl<T: ?Sized + Display, '_> Display for RefMut<'_, T>
[src]
impl<T: ?Sized, '_> Deref for RefMut<'_, T>
[src]
impl<T: ?Sized, '_> DerefMut for RefMut<'_, T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,