@@ -86,9 +86,10 @@ impl<T> Array<T> {
86
86
self . dims
87
87
. iter ( )
88
88
. zip ( indices. iter ( ) . cloned ( ) )
89
+ . rev ( )
89
90
. fold ( ( 0 , 1 ) , |( acc, stride) , ( dim, idx) | {
90
91
let shifted = dim. shift ( idx) ;
91
- ( acc * stride + shifted, dim. len )
92
+ ( acc + shifted * stride , dim. len * stride )
92
93
} )
93
94
. 0
94
95
}
@@ -160,6 +161,31 @@ tuple_impl!(a: isize, b: isize, c: isize, d: isize, e: isize, f: isize, g: isize
160
161
impl < T , I : ArrayIndex > Index < I > for Array < T > {
161
162
type Output = T ;
162
163
164
+ //github.com/ Indexes into the `Array`, retrieving a reference to the contained
165
+ //github.com/ value.
166
+ //github.com/
167
+ //github.com/ Since `Array`s can be multi-dimensional, the `Index` trait is
168
+ //github.com/ implemented for a variety of index types. In the most generic case, a
169
+ //github.com/ `&[isize]` can be used. In addition, a bare `isize` as well as tuples
170
+ //github.com/ of up to 10 `isize` values may be used for convenience.
171
+ //github.com/
172
+ //github.com/ # Panics
173
+ //github.com/
174
+ //github.com/ Panics if the index does not correspond to an in-bounds element of the
175
+ //github.com/ `Array`.
176
+ //github.com/
177
+ //github.com/ # Examples
178
+ //github.com/
179
+ //github.com/ ```rust
180
+ //github.com/ # use postgres_array::Array;
181
+ //github.com/ let mut array = Array::from_vec(vec![0i32, 1, 2, 3], 0);
182
+ //github.com/ assert_eq!(2, array[2]);
183
+ //github.com/
184
+ //github.com/ array.wrap(0);
185
+ //github.com/ array.push(Array::from_vec(vec![4, 5, 6, 7], 0));
186
+ //github.com/
187
+ //github.com/ assert_eq!(6, array[(1, 2)]);
188
+ //github.com/ ```
163
189
fn index ( & self , idx : I ) -> & T {
164
190
let idx = idx. index ( self ) ;
165
191
& self . data [ idx]
0 commit comments