mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-03 09:57:23 +00:00
Storage tracing (#3614)
* Storage tracing * Whitepsaces Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Apply suggestions from code review Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Update Cargo.lock
This commit is contained in:
@@ -21,28 +21,37 @@ pub struct HexDisplay<'a>(&'a [u8]);
|
||||
|
||||
impl<'a> HexDisplay<'a> {
|
||||
/// Create new instance that will display `d` as a hex string when displayed.
|
||||
pub fn from(d: &'a dyn AsBytesRef) -> Self { HexDisplay(d.as_bytes_ref()) }
|
||||
pub fn from<R: AsBytesRef>(d: &'a R) -> Self { HexDisplay(d.as_bytes_ref()) }
|
||||
}
|
||||
|
||||
impl<'a> ::core::fmt::Display for HexDisplay<'a> {
|
||||
fn fmt(&self, fmtr: &mut ::core::fmt::Formatter) -> Result<(), ::core::fmt::Error> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
|
||||
if self.0.len() < 1027 {
|
||||
for byte in self.0 {
|
||||
fmtr.write_fmt(format_args!("{:02x}", byte))?;
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
} else {
|
||||
for byte in &self.0[0..512] {
|
||||
fmtr.write_fmt(format_args!("{:02x}", byte))?;
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
fmtr.write_str("...")?;
|
||||
f.write_str("...")?;
|
||||
for byte in &self.0[self.0.len() - 512..] {
|
||||
fmtr.write_fmt(format_args!("{:02x}", byte))?;
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> core::fmt::Debug for HexDisplay<'a> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
|
||||
for byte in self.0 {
|
||||
f.write_fmt(format_args!("{:02x}", byte))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple trait to transform various types to `&[u8]`
|
||||
pub trait AsBytesRef {
|
||||
/// Transform `self` into `&[u8]`.
|
||||
|
||||
Reference in New Issue
Block a user