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:
parent
5b0686f09a
commit
baffe8fdf3
@ -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,
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user