summaryrefslogtreecommitdiffstats
path: root/openpgp/src/fmt.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-01-06 17:54:33 +0100
committerJustus Winter <justus@sequoia-pgp.org>2020-01-06 17:54:33 +0100
commitfe16487556c2b4d16400515aea8c448b0890e74c (patch)
treed574f9796338932d2fbe9bbf89d33031e122a551 /openpgp/src/fmt.rs
parent355494eb8e9a168a8e4c048d64b4ea43ac40b9bb (diff)
openpgp: Make hex::Dumper::write* polymorphic.
- See #229.
Diffstat (limited to 'openpgp/src/fmt.rs')
-rw-r--r--openpgp/src/fmt.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/openpgp/src/fmt.rs b/openpgp/src/fmt.rs
index 643750dc..429f2b69 100644
--- a/openpgp/src/fmt.rs
+++ b/openpgp/src/fmt.rs
@@ -74,12 +74,15 @@ pub mod hex {
/// Writes a chunk of data.
///
/// The `msg` is printed at the end of the first line.
- pub fn write(&mut self, buf: &[u8], msg: &str) -> io::Result<()> {
+ pub fn write<B, M>(&mut self, buf: B, msg: M) -> io::Result<()>
+ where B: AsRef<[u8]>,
+ M: AsRef<str>,
+ {
let mut first = true;
- self.write_labeled(buf, move |_, _| {
+ self.write_labeled(buf.as_ref(), move |_, _| {
if first {
first = false;
- Some(msg.into())
+ Some(msg.as_ref().into())
} else {
None
}
@@ -92,10 +95,12 @@ pub mod hex {
/// 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.
- pub fn write_labeled<L>(&mut self, buf: &[u8], mut labeler: L)
+ pub fn write_labeled<B, L>(&mut self, buf: B, mut labeler: L)
-> io::Result<()>
- where L: FnMut(usize, &[u8]) -> Option<String>
+ where B: AsRef<[u8]>,
+ L: FnMut(usize, &[u8]) -> Option<String>,
{
+ let buf = buf.as_ref();
let mut first_label_offset = self.offset % 16;
write!(self.inner, "{}{:08x} ", self.indent, self.offset)?;