style(core/rust): less expensive conversion from known good utf8 string

pull/2462/head
matejcik 2 years ago committed by matejcik
parent 0fb66d3527
commit 0b4ccf45fc

@ -1,3 +1,4 @@
use core::str;
use cstr_core::CStr;
use super::ffi;
@ -25,6 +26,6 @@ pub fn button_sequence_to_word(prefix: u16) -> Option<&'static str> {
} else {
// SAFETY: On success, `button_sequence_to_word` should return a 0-terminated
// UTF-8 string with static lifetime.
Some(unsafe { CStr::from_ptr(word).to_str().unwrap_unchecked() })
Some(unsafe { str::from_utf8_unchecked(CStr::from_ptr(word).to_bytes()) })
}
}

Loading…
Cancel
Save