pub trait VectorViewMut<T: ?Sized>: VectorView<T> {
// Required method
fn at_mut(&mut self, i: usize) -> &mut T;
// Provided methods
fn map_mut<F_const: for<'a> Fn(&'a T) -> &'a U, F_mut: for<'a> FnMut(&'a mut T) -> &'a mut U, U>(
self,
map_const: F_const,
map_mut: F_mut,
) -> VectorViewMapMut<Self, T, U, F_const, F_mut>
where Self: Sized { ... }
fn as_slice_mut<'a>(&'a mut self) -> Option<&'a mut [T]>
where T: Sized { ... }
unsafe fn at_unchecked_mut<'a>(&mut self, i: usize) -> &mut T { ... }
}
Expand description
A trait for VectorView
s that allow mutable access to one element at a time.
Note that a fundamental difference to many containers (like &mut [T]
) is that
this trait only defines functions that give a mutable reference to one element at
a time. In particular, it is intentionally impossible to have a mutable reference
to multiple elements at once. This enables implementations like sparse vectors,
e.g. sparse::SparseMapVector
.
Required Methods§
Provided Methods§
fn map_mut<F_const: for<'a> Fn(&'a T) -> &'a U, F_mut: for<'a> FnMut(&'a mut T) -> &'a mut U, U>(
self,
map_const: F_const,
map_mut: F_mut,
) -> VectorViewMapMut<Self, T, U, F_const, F_mut>where
Self: Sized,
Sourcefn as_slice_mut<'a>(&'a mut self) -> Option<&'a mut [T]>where
T: Sized,
fn as_slice_mut<'a>(&'a mut self) -> Option<&'a mut [T]>where
T: Sized,
If the underlying data of this VectorView
can be represented as a slice,
returns it. Otherwise, None
is returned.
Sourceunsafe fn at_unchecked_mut<'a>(&mut self, i: usize) -> &mut T
unsafe fn at_unchecked_mut<'a>(&mut self, i: usize) -> &mut T
Returns a refernce to the i
-th entry of the vector view, causing
UB if i >= self.len()
.
§Safety
Same as for slice::get_unchecked_mut()
. More concretely, calling this method with an out-of-bounds index
is undefined behavior even if the resulting reference is not used.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.