add support for indexing (usize, usize)
This commit is contained in:
parent
31d6729879
commit
d0a7ee701a
2 changed files with 17 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "grid"
|
||||
version = "0.9.1-alpha.0"
|
||||
version = "0.9.1-alpha.1"
|
||||
authors = ["Armin Becher <armin.becher@gmai.com>"]
|
||||
edition = "2018"
|
||||
description = "Dynamic generic 2D data structure."
|
||||
|
|
16
src/lib.rs
16
src/lib.rs
|
@ -801,6 +801,22 @@ impl<T> IndexMut<usize> for Grid<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Index<(usize, usize)> for Grid<T> {
|
||||
type Output = T;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, (x, y): (usize, usize)) -> &T {
|
||||
&self.data[y * self.cols + x]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IndexMut<(usize, usize)> for Grid<T> {
|
||||
#[inline]
|
||||
fn index_mut(&mut self, (x, y): (usize, usize)) -> &mut T {
|
||||
&mut self.data[y * self.cols + x]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Debug> fmt::Debug for Grid<T> {
|
||||
#[allow(unused_must_use)]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
|
Loading…
Reference in a new issue