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:
Arkadiy Paronyan
2019-09-17 20:42:15 +02:00
committed by GitHub
parent 2b040fe983
commit a07e567fe1
12 changed files with 223 additions and 41 deletions
+15 -6
View File
@@ -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]`.
+1 -1
View File
@@ -159,7 +159,7 @@ pub enum NativeOrEncoded<R> {
#[cfg(feature = "std")]
impl<R: codec::Encode> ::std::fmt::Debug for NativeOrEncoded<R> {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
self.as_encoded().as_ref().fmt(f)
hexdisplay::HexDisplay::from(&self.as_encoded().as_ref()).fmt(f)
}
}