From baffe8fdf313c054d48b2648f3d137632ef8ca57 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Fri, 26 Nov 2021 19:46:11 +0100 Subject: [PATCH] chore(core/rust): Add int variant to tracing --- core/embed/rust/src/trace.rs | 7 +++++++ core/embed/rust/src/ui/layout/obj.rs | 4 ++++ core/embed/rust/src/ui/model_t1/layout.rs | 4 ++++ core/embed/rust/src/ui/model_tt/layout.rs | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/core/embed/rust/src/trace.rs b/core/embed/rust/src/trace.rs index 2147f4489..b6a03bd8d 100644 --- a/core/embed/rust/src/trace.rs +++ b/core/embed/rust/src/trace.rs @@ -1,5 +1,6 @@ /// Visitor passed into `Trace` types. pub trait Tracer { + fn int(&mut self, i: i64); fn bytes(&mut self, b: &[u8]); fn string(&mut self, s: &str); fn symbol(&mut self, name: &str); @@ -25,6 +26,12 @@ impl Trace for &str { } } +impl Trace for usize { + fn trace(&self, t: &mut dyn Tracer) { + t.int(*self as i64); + } +} + impl Trace for Option where T: Trace, diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs index 94638df46..1e9a14929 100644 --- a/core/embed/rust/src/ui/layout/obj.rs +++ b/core/embed/rust/src/ui/layout/obj.rs @@ -169,6 +169,10 @@ impl LayoutObj { struct CallbackTracer(Obj); impl Tracer for CallbackTracer { + fn int(&mut self, i: i64) { + self.0.call_with_n_args(&[i.try_into().unwrap()]).unwrap(); + } + fn bytes(&mut self, b: &[u8]) { self.0.call_with_n_args(&[b.try_into().unwrap()]).unwrap(); } diff --git a/core/embed/rust/src/ui/model_t1/layout.rs b/core/embed/rust/src/ui/model_t1/layout.rs index 3f28a0070..1bcec5eff 100644 --- a/core/embed/rust/src/ui/model_t1/layout.rs +++ b/core/embed/rust/src/ui/model_t1/layout.rs @@ -84,6 +84,10 @@ mod tests { use super::*; impl Tracer for Vec { + fn int(&mut self, i: i64) { + self.string(&i.to_string()); + } + fn bytes(&mut self, b: &[u8]) { self.extend(b) } diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 5b3dcf817..507cd9ab5 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -59,6 +59,10 @@ mod tests { use super::*; impl Tracer for Vec { + fn int(&mut self, i: i64) { + self.string(&i.to_string()); + } + fn bytes(&mut self, b: &[u8]) { self.extend(b) }