pub struct VecMut<'a, T> { /* private fields */ }Expand description
A reference to a single column/row of a matrix.
This is similar to &[T] but with a pitch potentially different from 1 between its elements,
i.e. there is no guarantee of contiguity. As a consequence this does not have a simple
past-the-end pointer like a slice would have. For an empty slice the only guaranteed-valid
pointer is the base pointer itself while for larger slices the last guaranteed-valid pointer is
one-past the last element, not one additional pitch.
Created from its constructors or a block reference via the BlockMut::col and
BlockMut::row methods.
Implementations§
Source§impl<'data, T> VecMut<'data, T>
impl<'data, T> VecMut<'data, T>
Sourcepub fn new(data: &'data mut [T], pitch: usize) -> Self
pub fn new(data: &'data mut [T], pitch: usize) -> Self
Create a new vector reference from a raw slice and pitch.
The resulting block refers to the first column of the matrix.
Sourcepub fn from_slice(data: &'data mut [T]) -> Self
pub fn from_slice(data: &'data mut [T]) -> Self
Create a new vector reference from a raw slice with pitch 1.
Sourcepub fn split_at(self, mid: usize) -> (VecMut<'data, T>, VecMut<'data, T>)
pub fn split_at(self, mid: usize) -> (VecMut<'data, T>, VecMut<'data, T>)
Divide into two vectors at the given element.
§Examples
use matrix_slice::VecMut;
let data = &mut [0, 1, 2, 3, 4, 5];
let block = VecMut::new(data, 1);
let (left, right) = block.split_at(2);
assert_eq!(left[1], 1);
assert_eq!(right[3], 5);Sourcepub fn split_at_checked(
self,
mid: usize,
) -> Option<(VecMut<'data, T>, VecMut<'data, T>)>
pub fn split_at_checked( self, mid: usize, ) -> Option<(VecMut<'data, T>, VecMut<'data, T>)>
Divide into two vectors at the given element.
See Self::split_at but returns None if out of bounds.
Sourcepub fn split_off<R>(&mut self, range: R) -> Option<Self>where
R: OneSidedMatrixIndex,
pub fn split_off<R>(&mut self, range: R) -> Option<Self>where
R: OneSidedMatrixIndex,
Take part of the vector.
§Examples
use matrix_slice::VecMut;
let data = &mut [0, 1, 2, 3, 4, 5];
let mut vec = VecMut::new(data, 1);
// Does nothing.
assert!(vec.split_off(6..).is_some_and(|v| v.is_empty()));
assert!(vec.split_off(7..).is_none());
assert!(vec.split_off(..7).is_none());
let mut right = vec.split_off(2..).unwrap();
assert_eq!(vec.len(), 2);
assert_eq!(right[3], 5);
// The two halves are disjoint:
right[0] = 0x42;
assert_eq!(vec[1], 1);You can also split off the start:
use matrix_slice::VecMut;
let data = &mut [0, 1, 2, 3, 4, 5];
let mut vec = VecMut::new(data, 1);
let start = vec.split_off(..=2).unwrap();
assert_eq!(vec[0], 3);
assert_eq!(start[0], 0);Sourcepub fn select<R>(self, range: R) -> Option<VecMut<'data, T>>where
R: MatrixIndex,
pub fn select<R>(self, range: R) -> Option<VecMut<'data, T>>where
R: MatrixIndex,
Choose a range of elements and contract the vector to that.
Sourcepub fn cast_const(self) -> VecRef<'data, T>
pub fn cast_const(self) -> VecRef<'data, T>
Turn this unique reference into a shared reference.
Sourcepub fn reborrow(&mut self) -> VecMut<'_, T>
pub fn reborrow(&mut self) -> VecMut<'_, T>
Create a unique reference to this block with a shorter lifetime.
Sourcepub fn as_cells(self) -> VecMut<'data, Cell<T>>
pub fn as_cells(self) -> VecMut<'data, Cell<T>>
Modify the item type to a Cell, allowing interior mutability.
This is the equivalent of Cell::from_mut over elements in this slice.
Sourcepub fn iter(self) -> IterVecMut<'data, T> ⓘ
pub fn iter(self) -> IterVecMut<'data, T> ⓘ
§Examples
let data = &mut [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
];
let mut block = matrix_slice::from_array_rows_mut(data);
for item in block.reborrow().col(1) {
*item *= 2;
}
assert!(block.col(1).iter().eq(&[2, 8, 14]));Source§impl<'data, T> VecMut<'data, Cell<T>>
impl<'data, T> VecMut<'data, Cell<T>>
Sourcepub fn as_cell_items(self) -> VecMut<'data, T>
pub fn as_cell_items(self) -> VecMut<'data, T>
Modify the item type from a Cell to its interior type.
This is the equivalent of Cell::get_mut over elements in this slice.