@@ -94,6 +94,46 @@ impl<S, D, I> IndexMut<I> for ArrayBase<S, D>
94
94
}
95
95
}
96
96
97
+ impl < ' a , A , D > ArrayView < ' a , A , D >
98
+ where
99
+ D : Dimension ,
100
+ {
101
+ /// Get a reference of a element through the view.
102
+ ///
103
+ /// This is a replacement of `Index::index` since it forces us a wrong lifetime
104
+ /// https://github.com/bluss/rust-ndarray/issues/371
105
+ pub fn elem_ref < I : NdIndex < D > > ( & self , index : I ) -> & ' a A {
106
+ debug_bounds_check ! ( self , index) ;
107
+ unsafe {
108
+ & * self . as_ptr ( ) . offset (
109
+ index
110
+ . index_checked ( & self . dim , & self . strides )
111
+ . unwrap_or_else ( || array_out_of_bounds ( ) ) ,
112
+ )
113
+ }
114
+ }
115
+ }
116
+
117
+ impl < ' a , A , D > ArrayViewMut < ' a , A , D >
118
+ where
119
+ D : Dimension ,
120
+ {
121
+ /// Get a mutable reference of a element through the view.
122
+ ///
123
+ /// This is a replacement of `IndexMut::index_mut` since it forces us a wrong lifetime
124
+ /// https://github.com/bluss/rust-ndarray/issues/371
125
+ pub fn elem_ref_mut < I : NdIndex < D > > ( & mut self , index : I ) -> & ' a mut A {
126
+ debug_bounds_check ! ( self , index) ;
127
+ unsafe {
128
+ & mut * self . as_mut_ptr ( ) . offset (
129
+ index
130
+ . index_checked ( & self . dim , & self . strides )
131
+ . unwrap_or_else ( || array_out_of_bounds ( ) ) ,
132
+ )
133
+ }
134
+ }
135
+ }
136
+
97
137
/// Return `true` if the array shapes and all elements of `self` and
98
138
/// `rhs` are equal. Return `false` otherwise.
99
139
impl < S , S2 , D > PartialEq < ArrayBase < S2 , D > > for ArrayBase < S , D >
0 commit comments