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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use super::*;
use crate::col::ColMut;

/// Diagonal mutable matrix view.
pub struct DiagMut<'a, E: Entity> {
    pub(crate) inner: ColMut<'a, E>,
}

impl<'a, E: Entity> DiagMut<'a, E> {
    /// Returns the diagonal as a mutable column vector view.
    #[inline(always)]
    pub fn column_vector_mut(self) -> ColMut<'a, E> {
        self.inner
    }

    /// Returns a view over the matrix.
    #[inline]
    pub fn as_ref(&self) -> DiagRef<'_, E> {
        self.rb()
    }

    /// Returns a mutable view over the matrix.
    #[inline]
    pub fn as_mut(&mut self) -> DiagMut<'_, E> {
        self.rb_mut()
    }
}

impl<'short, E: Entity> Reborrow<'short> for DiagMut<'_, E> {
    type Target = DiagRef<'short, E>;

    #[inline]
    fn rb(&'short self) -> Self::Target {
        DiagRef {
            inner: self.inner.rb(),
        }
    }
}

impl<'short, E: Entity> ReborrowMut<'short> for DiagMut<'_, E> {
    type Target = DiagMut<'short, E>;

    #[inline]
    fn rb_mut(&'short mut self) -> Self::Target {
        DiagMut {
            inner: self.inner.rb_mut(),
        }
    }
}

impl<'a, E: Entity> IntoConst for DiagMut<'a, E> {
    type Target = DiagRef<'a, E>;

    #[inline]
    fn into_const(self) -> Self::Target {
        DiagRef {
            inner: self.inner.into_const(),
        }
    }
}