1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-31 02:48:44 +00:00

rust: add useful macros

This commit is contained in:
grdddj 2023-03-30 18:53:40 +02:00
parent a6d1dcbb03
commit d34c1eed75

View File

@ -4,3 +4,23 @@ macro_rules! include_res {
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/ui/", $filename))
};
}
#[allow(unused_macros)] // Only used in TR so far.
/// Concatenates arbitrary amount of slices into a String.
macro_rules! build_string {
($max:expr, $($string:expr),+) => {
{
let mut new_string = String::<$max>::new();
$(new_string.push_str($string).unwrap();)+
new_string
}
}
}
#[allow(unused_macros)] // Mostly for debugging purposes.
/// Transforms integer into string slice. For example for printing.
macro_rules! inttostr {
($int:expr) => {{
heapless::String::<10>::from($int).as_str()
}};
}