mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
rename convert to map
also use the fact that T is known to be Copy
This commit is contained in:
parent
bd0ecd77d2
commit
593a975d5c
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,13 +111,19 @@ impl<T: PrimitiveGridType> PrimitiveGrid<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert between PrimitiveGrid types
|
||||
pub fn convert<TConverted, F>(&self, f: F) -> PrimitiveGrid<TConverted>
|
||||
/// Convert between PrimitiveGrid types.
|
||||
///
|
||||
/// See also [Iterator::map].
|
||||
pub fn map<TConverted, F>(&self, f: F) -> PrimitiveGrid<TConverted>
|
||||
where
|
||||
TConverted: PrimitiveGridType,
|
||||
F: FnMut(&T) -> TConverted,
|
||||
F: Fn(T) -> TConverted,
|
||||
{
|
||||
let data = self.data_ref().iter().map(f).collect::<Vec<_>>();
|
||||
let data = self
|
||||
.data_ref()
|
||||
.iter()
|
||||
.map(|elem| f(*elem))
|
||||
.collect::<Vec<_>>();
|
||||
PrimitiveGrid::load(self.width(), self.height(), &data)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue