1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

chore(core/rust): Add int variant to tracing

This commit is contained in:
Jan Pochyla 2021-11-26 19:46:11 +01:00 committed by matejcik
parent 5b0686f09a
commit baffe8fdf3
4 changed files with 19 additions and 0 deletions

View File

@ -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<T> Trace for Option<T>
where
T: Trace,

View File

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

View File

@ -84,6 +84,10 @@ mod tests {
use super::*;
impl Tracer for Vec<u8> {
fn int(&mut self, i: i64) {
self.string(&i.to_string());
}
fn bytes(&mut self, b: &[u8]) {
self.extend(b)
}

View File

@ -59,6 +59,10 @@ mod tests {
use super::*;
impl Tracer for Vec<u8> {
fn int(&mut self, i: i64) {
self.string(&i.to_string());
}
fn bytes(&mut self, b: &[u8]) {
self.extend(b)
}