Skip to content

Commit

Permalink
Fix rust clippy complains
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Nov 17, 2023
1 parent c7fa662 commit 9a219ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
27 changes: 26 additions & 1 deletion rust/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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")?;
Expand Down Expand Up @@ -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<u64>, 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))?,
Expand Down
2 changes: 1 addition & 1 deletion typescript/r2papi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9a219ea

Please sign in to comment.