Is there a trait applicable for multi-dimensional indexing?
Hi all.
Does anyone know if there is a trait that would be applicable to multi-dimensional indexing, such as this: x[y][z].
The closest I've found is something like this, which seems is syntactically less efficient:
impl Index<(usize, usize)> for Matrix {
type Output = f32;
fn index(&self, index: (usize, usize)) -> &Self::Output {
assert!(index.0 < self.row_count() && index.1 < self.column_count());
&self.m[index.0][index.1]
}
}
Which can be accessed like this: matrix[(i, j)]. As I said, the syntax seems less efficient than purely matrix[i][j].
Any ideas?