matreex/matrix/
order.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// Represents the memory order of a matrix.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Order {
    #[default]
    RowMajor,
    ColMajor,
}

impl Order {
    pub fn switch(&mut self) -> &mut Self {
        *self = match self {
            Self::RowMajor => Self::ColMajor,
            Self::ColMajor => Self::RowMajor,
        };
        self
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_switch() {
        let mut order = Order::RowMajor;

        order.switch();
        assert_eq!(order, Order::ColMajor);

        order.switch();
        assert_eq!(order, Order::RowMajor);
    }
}