Skip to content

Commit 294f6be

Browse files
committed
fix(map): couldn't index into Map because inner was private??
1 parent 118ed20 commit 294f6be

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/map.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use crate::points::Point2D;
1010
pub struct Map2D<T>(Vec<Vec<T>>);
1111

1212
impl<T> Map2D<T> {
13+
pub fn new(v: Vec<Vec<T>>) -> Self {
14+
Self(v)
15+
}
1316
pub fn height(&self) -> usize {
1417
self.0.len()
1518
}
@@ -41,6 +44,18 @@ where
4144
}
4245
}
4346

47+
/// ```rust
48+
/// # use libaoc::{map::Map2D, points::Point2D};
49+
/// let v = vec![
50+
/// vec![1, 2, 3],
51+
/// vec![4, 5, 6],
52+
/// vec![7, 8, 9]
53+
/// ];
54+
/// let m = Map2D::new(v);
55+
/// let pos: Point2D<usize> = Point2D(1, 2);
56+
///
57+
/// assert_eq!(m[pos], 8);
58+
/// ```
4459
impl<T, U> Index<Point2D<T>> for Map2D<U>
4560
where
4661
T: Into<usize>,

0 commit comments

Comments
 (0)