[][src]Struct cell::RefMut

pub struct RefMut<'b, T: ?Sized + 'b> { /* fields omitted */ }

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]

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]

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]

type Target = T

The resulting type after dereferencing.

impl<T: ?Sized, '_> DerefMut for RefMut<'_, T>[src]

Auto Trait Implementations

impl<'b, T> !Send for RefMut<'b, T>

impl<'b, T> !Sync for RefMut<'b, T>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]