pub struct VecRef<'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 BlockRef::col and
BlockRef::row methods.
Implementations§
Source§impl<'data, T> VecRef<'data, T>
impl<'data, T> VecRef<'data, T>
Sourcepub fn new(data: &'data [T], pitch: usize) -> Self
pub fn new(data: &'data [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.
§Panics
Panics if the pitch is zero.
Sourcepub fn from_slice(data: &'data [T]) -> Self
pub fn from_slice(data: &'data [T]) -> Self
Create a new vector reference from a raw slice with pitch 1.
Sourcepub fn split_at(self, mid: usize) -> (VecRef<'data, T>, VecRef<'data, T>)
pub fn split_at(self, mid: usize) -> (VecRef<'data, T>, VecRef<'data, T>)
Divide into two vectors at the given element.
§Examples
use matrix_slice::VecRef;
let data = &[0, 1, 2, 3, 4, 5];
let block = VecRef::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<(VecRef<'data, T>, VecRef<'data, T>)>
pub fn split_at_checked( self, mid: usize, ) -> Option<(VecRef<'data, T>, VecRef<'data, T>)>
Divide into two vectors at the given element.
See Self::split_at but returns None if out of bounds.
Sourcepub fn select<R>(self, range: R) -> Option<VecRef<'data, T>>where
R: MatrixIndex,
pub fn select<R>(self, range: R) -> Option<VecRef<'data, T>>where
R: MatrixIndex,
Choose a range of elements and contract the vector to that.