Browse Source

[u8] to utf16 String

pull/3/head
jake 5 years ago
parent
commit
a03aadfadf
  1. 7
      src/util.rs

7
src/util.rs

@ -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…
Cancel
Save