[u8] to utf16 String
This commit is contained in:
		
							parent
							
								
									d8b6953edb
								
							
						
					
					
						commit
						a03aadfadf
					
				@ -9,6 +9,13 @@ pub fn array_to_utf8<const X: usize>(array: [u8; X]) -> Result<String, std::stri
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn array_to_utf16(array: &[u8]) -> String {
 | 
				
			||||||
 | 
					    unsafe {
 | 
				
			||||||
 | 
					        let (_, data, _) = array.align_to();
 | 
				
			||||||
 | 
					        String::from_utf16_lossy(&data).trim_matches(char::from(0)).into()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: const fn version of this! (helpful with tests)
 | 
					// TODO: const fn version of this! (helpful with tests)
 | 
				
			||||||
#[macro_export]
 | 
					#[macro_export]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user