pub struct GcCellRefMut<'a, T: Trace + ?Sized + 'static, U: ?Sized = T> { /* private fields */ }
Expand description
A wrapper type for a mutably borrowed value from a GcCell<T>
.
Implementations§
Source§impl<'a, T: Trace + ?Sized, U: ?Sized> GcCellRefMut<'a, T, U>
impl<'a, T: Trace + ?Sized, U: ?Sized> GcCellRefMut<'a, T, U>
Sourcepub fn map<V, F>(orig: Self, f: F) -> GcCellRefMut<'a, T, V>
pub fn map<V, F>(orig: Self, f: F) -> GcCellRefMut<'a, T, V>
Makes a new GcCellRefMut
for a component of the borrowed data, e.g., an enum
variant.
The GcCell
is already mutably borrowed, so this cannot fail.
This is an associated function that needs to be used as
GcCellRefMut::map(...)
. A method would interfere with methods of the same
name on the contents of a GcCell
used through Deref
.
§Examples
use gc::{GcCell, GcCellRefMut};
let c = GcCell::new((5, 'b'));
{
let b1: GcCellRefMut<(u32, char)> = c.borrow_mut();
let mut b2: GcCellRefMut<(u32, char), u32> = GcCellRefMut::map(b1, |t| &mut t.0);
assert_eq!(*b2, 5);
*b2 = 42;
}
assert_eq!(*c.borrow(), (42, 'b'));
Sourcepub fn filter_map<V, F>(
orig: Self,
f: F,
) -> Result<GcCellRefMut<'a, T, V>, Self>
pub fn filter_map<V, F>( orig: Self, f: F, ) -> Result<GcCellRefMut<'a, T, V>, Self>
Makes a new GcCellRefMut
for an optional component of the borrowed
data. The original guard is returned as an Err(..)
if the closure
returns None
.
The GcCell
is already mutably borrowed, so this cannot fail.
This is an associated function that needs to be used as
GcCellRefMut::filter_map(...)
. A method would interfere with methods
of the same name on the contents of a GcCell
used through Deref
.
§Examples
use gc::{GcCell, GcCellRefMut};
let c = GcCell::new(vec![1, 2, 3]);
{
let b1: GcCellRefMut<Vec<u32>> = c.borrow_mut();
let mut b2: Result<GcCellRefMut<Vec<u32>, u32>, _> = GcCellRefMut::filter_map(b1, |v| v.get_mut(1));
if let Ok(mut b2) = b2 {
*b2 += 2;
}
}
assert_eq!(*c.borrow(), vec![1, 4, 3]);