Use Formatter debug helpers.

This commit is contained in:
Andreas Fackler 2018-09-03 11:58:54 +02:00 committed by Andreas Fackler
parent b649dc6268
commit 05b04bba39
3 changed files with 12 additions and 8 deletions

View File

@ -50,9 +50,9 @@ impl rand::Rand for Message {
impl Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Message::Value(ref v) => write!(f, "Value({:?})", HexProof(&v)),
Message::Echo(ref v) => write!(f, "Echo({:?})", HexProof(&v)),
Message::Ready(ref bytes) => write!(f, "Ready({:?})", HexBytes(bytes)),
Message::Value(ref v) => f.debug_tuple("Value").field(&HexProof(v)).finish(),
Message::Echo(ref v) => f.debug_tuple("Echo").field(&HexProof(v)).finish(),
Message::Ready(ref b) => f.debug_tuple("Ready").field(&HexBytes(b)).finish(),
}
}
}

View File

@ -30,7 +30,7 @@ pub struct HexList<'a, T: 'a>(pub &'a [T]);
impl<'a, T: AsRef<[u8]>> fmt::Debug for HexList<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let v: Vec<_> = self.0.iter().map(|t| HexBytes(t.as_ref())).collect();
write!(f, "{:?}", v)
v.fmt(f)
}
}

View File

@ -199,9 +199,10 @@ pub struct Part(BivarCommitment, Vec<Ciphertext>);
impl Debug for Part {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let deg = self.0.degree();
let len = self.1.len();
write!(f, "Part(<degree {}>, <{} rows>)", deg, len)
f.debug_tuple("Part")
.field(&format!("<degree {}>", self.0.degree()))
.field(&format!("<{} rows>", self.1.len()))
.finish()
}
}
@ -215,7 +216,10 @@ pub struct Ack(u64, Vec<Ciphertext>);
impl Debug for Ack {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "Ack({}, <{} values>", self.0, self.1.len())
f.debug_tuple("Ack")
.field(&self.0)
.field(&format!("<{} values>", self.1.len()))
.finish()
}
}