changed name of Map to World, to avoid confusion with the list comprehension

This commit is contained in:
sepia 2024-12-16 20:38:42 -06:00
parent 965bdca334
commit 62ff4680a5
4 changed files with 24 additions and 24 deletions

View file

@ -48,16 +48,16 @@ impl Direction {
}
#[derive(Clone)]
pub struct Map<T>
pub struct World<T>
where
T: Copy,
{
pub map: Vec<Vec<T>>,
}
impl Map<char> {
impl World<char> {
pub fn from_string(string: &str) -> Self {
Map::from_2d_vec(
World::from_2d_vec(
string
.lines()
.filter(|line| !line.is_empty())
@ -67,7 +67,7 @@ impl Map<char> {
}
}
impl<T> Map<T>
impl<T> World<T>
where
T: Copy,
{
@ -153,13 +153,13 @@ where
self.coordinates().map(|(x, y)| (x, y, &self.map[y][x]))
}
pub fn map<U: Copy, F: Fn(&T) -> U>(&self, f: F) -> Map<U> {
pub fn map<U: Copy, F: Fn(&T) -> U>(&self, f: F) -> World<U> {
let v = self.map.iter().map(|row| row.iter().map(|e| f(e)).collect()).collect();
Map::<U>::from_2d_vec(v)
World::<U>::from_2d_vec(v)
}
}
impl<T> Display for Map<T>
impl<T> Display for World<T>
where
T: Copy + Display,
{