From d34c1eed75dc9dc89dc1ffe8c18526163695ec22 Mon Sep 17 00:00:00 2001 From: grdddj Date: Thu, 30 Mar 2023 18:53:40 +0200 Subject: [PATCH] rust: add useful macros --- core/embed/rust/src/ui/macros.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/embed/rust/src/ui/macros.rs b/core/embed/rust/src/ui/macros.rs index 8ccea9d9c8..033157fa81 100644 --- a/core/embed/rust/src/ui/macros.rs +++ b/core/embed/rust/src/ui/macros.rs @@ -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() + }}; +}