pub struct VecRefMut<'a, T: ?Sized> { /* private fields */ }
Expand description
Wraps a mutably borrowed value from a VecCell
.
Implementations
sourceimpl<'a, T: ?Sized> VecRefMut<'a, T>
impl<'a, T: ?Sized> VecRefMut<'a, T>
sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Returns an immutable reference to the borrowed value.
The reference may not outlive this VecRefMut
instance.
Example
let mut vec: VecCell<String> = VecCell::new();
vec.push(String::from("hello"));
vec.push(String::from("world"));
let guard = vec.borrow_mut(0).unwrap();
assert_eq!(guard.get(), "hello");
sourcepub fn map<'b, U: ?Sized, F>(
original: VecRefMut<'b, T>,
f: F
) -> VecRefMut<'b, U> where
F: FnOnce(&mut T) -> &mut U,
pub fn map<'b, U: ?Sized, F>(
original: VecRefMut<'b, T>,
f: F
) -> VecRefMut<'b, U> where
F: FnOnce(&mut T) -> &mut U,
Transforms a VecRefMut<'_, T>
into a VecRefMut<'_, U>
from a function that maps &mut T
to &mut U
.
This function does not use self
and must be called explicitly via VecRefMut::map(value, function)
.
Examples
fn return_favorite_value_mut<'a>(array: &'a VecCell<Vec<u8>>) -> VecRefMut<'a, u8> {
VecRefMut::map(array.borrow_mut(42).unwrap(), |vec| &mut vec[7])
}
sourcepub fn try_map<'b, U: ?Sized, F, E>(
original: VecRefMut<'b, T>,
f: F
) -> Result<VecRefMut<'b, U>, E> where
F: FnOnce(&mut T) -> Result<&mut U, E>,
pub fn try_map<'b, U: ?Sized, F, E>(
original: VecRefMut<'b, T>,
f: F
) -> Result<VecRefMut<'b, U>, E> where
F: FnOnce(&mut T) -> Result<&mut U, E>,
Variant of VecRefMut::map
, where the callback (f
) may fail.
f
must return a Result
; if it returns Ok(x)
, then try_map
returns Ok(VecRefMut(x))
.
Otherwise, it returns Err(err)
.
Trait Implementations
Auto Trait Implementations
impl<'a, T> !RefUnwindSafe for VecRefMut<'a, T>
impl<'a, T> !Send for VecRefMut<'a, T>
impl<'a, T> !Sync for VecRefMut<'a, T>
impl<'a, T: ?Sized> Unpin for VecRefMut<'a, T>
impl<'a, T> !UnwindSafe for VecRefMut<'a, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more