From 9a219ea22a573b5238d1868ce89fc5c860709d22 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 17 Nov 2023 12:10:12 +0100 Subject: [PATCH] Fix rust clippy complains --- rust/src/api.rs | 27 ++++++++++++++++++++++++++- typescript/r2papi.ts | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/rust/src/api.rs b/rust/src/api.rs index 25fa367..fa54295 100644 --- a/rust/src/api.rs +++ b/rust/src/api.rs @@ -6,6 +6,30 @@ use r2pipe::Error; use serde_json::from_str; use std::collections::HashMap; +use std::fmt; + +struct HexSlice<'a>(&'a [u8]); + +impl<'a> HexSlice<'a> { + fn new(data: &'a T) -> HexSlice<'a> + where + T: ?Sized + AsRef<[u8]> + 'a, + { + HexSlice(data.as_ref()) + } +} + +// You can choose to implement multiple traits, like Lower and UpperHex +impl fmt::Display for HexSlice<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for byte in self.0 { + // Decide if you want to pad the value or have spaces inbetween, etc. + write!(f, "{:02X} ", byte)?; + } + Ok(()) + } +} + impl R2PApi for R2 { fn analyze(&mut self) -> Result<(), Error> { self.send("aaa")?; @@ -295,7 +319,8 @@ impl R2PApi for R2 { /// Write bytes to a specified offset, or None for current position fn write_bytes(&mut self, offset: Option, bytes: &[u8]) -> Result<(), Error> { - let hex: String = bytes.iter().map(|b| format!("{:02X}", b)).collect(); + // let hex: String = bytes.iter().map(|b| format!("{:02X}", b)).collect(); + let hex: String = format!("{}", HexSlice::new(bytes)); match offset { Some(off) => self.send(&format!("wx {} @{}", hex, off))?, diff --git a/typescript/r2papi.ts b/typescript/r2papi.ts index 9b7d96b..6cb37ee 100644 --- a/typescript/r2papi.ts +++ b/typescript/r2papi.ts @@ -859,7 +859,7 @@ export class NativePointer { isNull(): boolean { return this.toNumber() == 0 } - /* + /** * Compare current pointer with the passed one, and return -1, 0 or 1. * * * if (this < arg) return -1;