2015-07-12 06:32:32 -05:00
|
|
|
use std::ops::Index;
|
|
|
|
|
|
|
|
pub trait Array2D: Index<usize> {
|
|
|
|
fn rows(&self) -> usize;
|
|
|
|
fn columns(&self) -> usize;
|
|
|
|
fn get<'a>(&'a self, y: usize, x: usize) -> Option<&'a <Self as Index<usize>>::Output> {
|
|
|
|
if y >= self.rows() || x >= self.columns() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let i = y * self.columns() + x;
|
|
|
|
let indexer = &(*self as &Index<usize, Output = <Self as Index<usize>>::Output>);
|
2017-06-09 15:04:29 -05:00
|
|
|
//~^ERROR non-primitive cast
|
2015-07-12 06:32:32 -05:00
|
|
|
Some(indexer.index(i))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|