rename convert to map
also use the fact that T is known to be Copy
This commit is contained in:
		
							parent
							
								
									bd0ecd77d2
								
							
						
					
					
						commit
						593a975d5c
					
				
					 2 changed files with 13 additions and 7 deletions
				
			
		|  | @ -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…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter