Remove dependency on hex (#21567)

* Remove dependency on `hex`

* Update lock file

* Use `debug_struct` instead of own format

* Share code, add test, and fix rent_epoch spelling

Co-authored-by: Tyera Eulberg <tyera@solana.com>
This commit is contained in:
fee1-dead
2021-12-04 11:53:35 +08:00
committed by GitHub
parent e130b2cffc
commit c4a9c8b5e9
8 changed files with 136 additions and 49 deletions

View File

@@ -0,0 +1,20 @@
use std::{cmp, fmt};
pub(crate) const MAX_DEBUG_ACCOUNT_DATA: usize = 64;
pub fn debug_account_data(data: &[u8], f: &mut fmt::DebugStruct<'_, '_>) {
let data_len = cmp::min(MAX_DEBUG_ACCOUNT_DATA, data.len());
if data_len > 0 {
f.field("data", &Hex(&data[..data_len]));
}
}
pub(crate) struct Hex<'a>(pub(crate) &'a [u8]);
impl fmt::Debug for Hex<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for &byte in self.0 {
write!(f, "{:02x}", byte)?;
}
Ok(())
}
}