Skip to main content

VecRef

Struct VecRef 

Source
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>

Source

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.

Source

pub fn from_slice(data: &'data [T]) -> Self

Create a new vector reference from a raw slice with pitch 1.

Source

pub fn len(&self) -> usize

Number of elements in this vector.

Source

pub fn is_empty(&self) -> bool

Whether this vector is empty.

Source

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);
Source

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.

Source

pub fn split_off<R>(&mut self, range: R) -> Option<Self>

Take part of the vector.

§Examples
use matrix_slice::VecRef;

let data = &[0, 1, 2, 3, 4, 5];
let mut vec = VecRef::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 right = vec.split_off(2..).unwrap();
assert_eq!(vec.len(), 2);
assert_eq!(right[3], 5);

You can also split off the start:

use matrix_slice::VecRef;

let data = &[0, 1, 2, 3, 4, 5];
let mut vec = VecRef::new(data, 1);
let start = vec.split_off(..=2).unwrap();

assert_eq!(vec[0], 3);
assert_eq!(start[0], 0);
Source

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.

Source

pub fn iter(self) -> IterVec<'data, T>

§Examples
let data = &[
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
];

let block = matrix_slice::from_array_rows(data);
let column = block.col(1);

assert!(column.iter().eq(&[1, 4, 7]));

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for VecRef<'a, T>

Source§

fn clone(&self) -> VecRef<'a, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Index<usize> for VecRef<'_, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'data, T> IntoIterator for VecRef<'data, T>

Source§

type Item = &'data T

The type of the elements being iterated over.
Source§

type IntoIter = IterVec<'data, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: Copy> Copy for VecRef<'a, T>

Source§

impl<T> Send for VecRef<'_, T>
where T: Sync,

Source§

impl<T> Sync for VecRef<'_, T>
where T: Sync,

Auto Trait Implementations§

§

impl<'a, T> Freeze for VecRef<'a, T>

§

impl<'a, T> RefUnwindSafe for VecRef<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Unpin for VecRef<'a, T>

§

impl<'a, T> UnwindSafe for VecRef<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.