1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-17 19:00:58 +00:00

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

This commit is contained in:
matejcik 2022-08-15 15:01:13 +02:00 committed by matejcik
parent 0fb66d3527
commit 0b4ccf45fc

View File

@ -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()) })
}
}