Struct NestedRefMut

Source
pub struct NestedRefMut<'a, T, N>
where T: ?Sized, N: ArrayLength<Ref<'a, ()>>,
{ /* private fields */ }
Expand description

Exclusive reference to data contained in one or more nested RefCells.

This has the same interface as RefMut, and unlike NestedRef cannot be nested further.

§Examples

// Create a `RefCell` two levels deep and a `NestedRefMut` into it
let rc = RefCell::new(RefCell::new(0));
let nr = NestedRef::new(rc.borrow());
let mut nr = NestedRef::map_ref_mut(nr, RefCell::borrow_mut);

// Mutate contained value
assert_eq!(*nr, 0);
*nr = 1;
assert_eq!(*nr, 1);

Implementations§

Source§

impl<'a, T> NestedRefMut<'a, T, U0>
where T: ?Sized,

Source

pub fn new(inner: RefMut<'a, T>) -> Self

Creates a new reference inside a single RefCell

Source§

impl<'a, T, N> NestedRefMut<'a, T, N>
where T: ?Sized, N: ArrayLength<Ref<'a, ()>>,

Source

pub fn map<U, F>(orig: Self, f: F) -> NestedRefMut<'a, U, N>
where U: ?Sized, F: FnOnce(&mut T) -> &mut U,

Creates a reference to a component of the borrowed data, like RefMut::map.

This is an associated function, because a method would interfere with methods of the same name on the contents of the RefCell.

Source

pub fn filter_map<U, F>( orig: Self, f: F, ) -> Result<NestedRefMut<'a, U, N>, Self>
where U: ?Sized, F: FnOnce(&mut T) -> Option<&mut U>,

Creates a reference to an optional component of the borrowed data, like RefMut::filter_map. The original reference is returned inside an Err if the closure returns None.

This is an associated function, because a method would interfere with methods of the same name on the contents of the RefCell.

Source

pub fn map_split<U, V, F>( orig: Self, f: F, ) -> (NestedRefMut<'a, U, N>, NestedRefMut<'a, V, N>)
where U: ?Sized, V: ?Sized, F: FnOnce(&mut T) -> (&mut U, &mut V),

Splits a reference into multiple references for different components of the borrowed data, like RefMut::map_split.

This is an associated function, because a method would interfere with methods of the same name on the contents of the RefCell.

Trait Implementations§

Source§

impl<'a, T, N> Deref for NestedRefMut<'a, T, N>
where T: ?Sized, N: ArrayLength<Ref<'a, ()>>,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T, N> DerefMut for NestedRefMut<'a, T, N>
where T: ?Sized, N: ArrayLength<Ref<'a, ()>>,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a, T, N> Freeze for NestedRefMut<'a, T, N>
where <N as ArrayLength<Ref<'a, ()>>>::ArrayType: Freeze, T: ?Sized,

§

impl<'a, T, N> !RefUnwindSafe for NestedRefMut<'a, T, N>

§

impl<'a, T, N> !Send for NestedRefMut<'a, T, N>

§

impl<'a, T, N> !Sync for NestedRefMut<'a, T, N>

§

impl<'a, T, N> Unpin for NestedRefMut<'a, T, N>
where <N as ArrayLength<Ref<'a, ()>>>::ArrayType: Unpin, T: ?Sized,

§

impl<'a, T, N> !UnwindSafe for NestedRefMut<'a, T, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.