diff --git a/crates/servicepoint/src/cp437.rs b/crates/servicepoint/src/cp437.rs index c6df59c..f757594 100644 --- a/crates/servicepoint/src/cp437.rs +++ b/crates/servicepoint/src/cp437.rs @@ -129,17 +129,17 @@ mod feature_cp437 { HashMap::from_iter(pairs) }); - const MISSING_CHAR_CP437: u8 = 0x3F; + const MISSING_CHAR_CP437: u8 = 0x3F; // '?' impl From<&Cp437Grid> for CharGrid { fn from(value: &Cp437Grid) -> Self { - value.convert(move |cp437| cp437_to_char(*cp437)) + value.map(cp437_to_char) } } impl From<&CharGrid> for Cp437Grid { fn from(value: &CharGrid) -> Self { - value.convert(move |char| char_to_cp437(*char)) + value.map(char_to_cp437) } } diff --git a/crates/servicepoint/src/primitive_grid.rs b/crates/servicepoint/src/primitive_grid.rs index ca2ce05..f58c44c 100644 --- a/crates/servicepoint/src/primitive_grid.rs +++ b/crates/servicepoint/src/primitive_grid.rs @@ -111,13 +111,19 @@ impl PrimitiveGrid { } } - /// Convert between PrimitiveGrid types - pub fn convert(&self, f: F) -> PrimitiveGrid + /// Convert between PrimitiveGrid types. + /// + /// See also [Iterator::map]. + pub fn map(&self, f: F) -> PrimitiveGrid where TConverted: PrimitiveGridType, - F: FnMut(&T) -> TConverted, + F: Fn(T) -> TConverted, { - let data = self.data_ref().iter().map(f).collect::>(); + let data = self + .data_ref() + .iter() + .map(|elem| f(*elem)) + .collect::>(); PrimitiveGrid::load(self.width(), self.height(), &data) } }