Struct sequoia_openpgp::fmt::hex::Dumper
source · pub struct Dumper<W: Write> { /* private fields */ }
Expand description
Writes annotated hex dumps, like hd(1).
§Examples
use sequoia_openpgp::fmt::hex;
let mut dumper = hex::Dumper::new(Vec::new(), "");
dumper.write(&[0x89, 0x01, 0x33], "frame")?;
dumper.write(&[0x04], "version")?;
dumper.write(&[0x00], "type")?;
let buf = dumper.into_inner();
assert_eq!(
::std::str::from_utf8(&buf[..])?,
"00000000 89 01 33 frame\n\
00000003 04 version\n\
00000004 00 type\n\
");
Implementations§
source§impl<W: Write> Dumper<W>
impl<W: Write> Dumper<W>
sourcepub fn new<I: AsRef<str>>(inner: W, indent: I) -> Self
pub fn new<I: AsRef<str>>(inner: W, indent: I) -> Self
Creates a new dumper.
The dump is written to inner
. Every line is indented with
indent
.
sourcepub fn with_offset<I>(inner: W, indent: I, offset: usize) -> Self
pub fn with_offset<I>(inner: W, indent: I, offset: usize) -> Self
Creates a new dumper starting at the given offset.
The dump is written to inner
. Every line is indented with
indent
.
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Returns the inner writer.
sourcepub fn write<B, M>(&mut self, buf: B, msg: M) -> Result<()>
pub fn write<B, M>(&mut self, buf: B, msg: M) -> Result<()>
Writes a chunk of data.
The msg
is printed at the end of the first line.
sourcepub fn write_ascii<B>(&mut self, buf: B) -> Result<()>
pub fn write_ascii<B>(&mut self, buf: B) -> Result<()>
Writes a chunk of data with ASCII-representation.
This produces output similar to hd(1)
.
sourcepub fn write_labeled<B, L>(&mut self, buf: B, labeler: L) -> Result<()>
pub fn write_labeled<B, L>(&mut self, buf: B, labeler: L) -> Result<()>
Writes a chunk of data.
For each line, the given function is called to compute a label that printed at the end of the first line. The functions first argument is the offset in the current line (0..16), the second the slice of the displayed data.
Auto Trait Implementations§
impl<W> Freeze for Dumper<W>where
W: Freeze,
impl<W> RefUnwindSafe for Dumper<W>where
W: RefUnwindSafe,
impl<W> Send for Dumper<W>where
W: Send,
impl<W> Sync for Dumper<W>where
W: Sync,
impl<W> Unpin for Dumper<W>where
W: Unpin,
impl<W> UnwindSafe for Dumper<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more