From a03aadfadf423621f9d5b782c02aa62d0b803d15 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 20 May 2020 23:21:43 -0600 Subject: [PATCH] [u8] to utf16 String --- src/util.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util.rs b/src/util.rs index 884ab1a..865416b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -9,6 +9,13 @@ pub fn array_to_utf8(array: [u8; X]) -> Result 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) #[macro_export]