From 25fd52be519def8ba984e7ce38957c10a0459220 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Thu, 19 Nov 2020 19:02:33 -0800 Subject: [PATCH] chain: tidy Debug for Amount This avoids printing a bunch of PhantomData. --- zebra-chain/src/amount.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/zebra-chain/src/amount.rs b/zebra-chain/src/amount.rs index 81a30b6fe..3e5071936 100644 --- a/zebra-chain/src/amount.rs +++ b/zebra-chain/src/amount.rs @@ -19,11 +19,21 @@ use byteorder::{ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt}; type Result = std::result::Result; /// A runtime validated type for representing amounts of zatoshis -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Clone, Copy, Serialize, Deserialize)] #[serde(try_from = "i64")] #[serde(bound = "C: Constraint")] pub struct Amount(i64, PhantomData); +// in a world where specialization existed +// https://github.com/rust-lang/rust/issues/31844 +// we could do much better here +// for now, drop the constraint +impl std::fmt::Debug for Amount { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("Amount").field(&self.0).finish() + } +} + impl Amount { /// Convert this amount to a different Amount type if it satisfies the new constraint pub fn constrain(self) -> Result>