h_mat/h_mat/
h_mat_ref.rs

1use crate::{AccessColRef, AccessRowRef, HCol};
2
3use super::{HColIter, Row};
4
5/// A reference to a `HMat` with arbitrarily ordered rows.
6#[derive(Clone, Copy, Debug)]
7pub struct HMatRef<'a, D, R> {
8    pub(crate) row: &'a Row<D>,
9    pub(crate) rem: R,
10}
11
12impl<'a, T, R> HMatRef<'a, T, R> {
13    /// Returns a reference to the `Row<D>` of this matrix slice.
14    pub fn get_row_ref<D, Directive>(&self) -> &Row<D>
15    where
16        Self: AccessRowRef<D, Directive>,
17    {
18        AccessRowRef::<D, Directive>::get_row_ref(self)
19    }
20
21    /// Returns a reference to the column at the given column index `col_idx`.
22    pub fn get_col_ref(&'a self, col_idx: usize) -> HCol<&T, <Self as AccessColRef<'a, T>>::Rem>
23    where
24        Self: AccessColRef<'a, T>,
25    {
26        AccessColRef::<'a, T>::get_col_ref(self, col_idx)
27    }
28
29    /// Returns an iterator that iterates over `num_cols` many columns, with the column indexes from `0` to `num_cols-1`.
30    pub fn iter(&'a self, num_cols: usize) -> HColIter<'a, Self>
31    where
32        Self: AccessColRef<'a, T>,
33    {
34        HColIter {
35            mat_ref: self,
36            curr_col_idx: 0,
37            num_cols,
38        }
39    }
40}