From 8f3094448e3f68f505221ed47bfa1fa946f6969f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 24 Feb 2021 22:07:52 -0800 Subject: [PATCH] Change Debug to match Display The derived `Debug` showed the raw digit data, which is sometimes useful if you're debugging `num-bigint` itself, but annoying in many other contexts. For something like a simple `dbg!` call in a program, you probably just want to see the numeric value. This is not _necessarily_ a breaking change, but we'll treat it so. --- src/bigint.rs | 7 ++++++- src/biguint.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index 4b0e4891..891eeb46 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -59,7 +59,6 @@ impl Neg for Sign { } /// A big signed integer type. -#[derive(Debug)] pub struct BigInt { sign: Sign, data: BigUint, @@ -137,6 +136,12 @@ impl Default for BigInt { } } +impl fmt::Debug for BigInt { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} + impl fmt::Display for BigInt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad_integral(!self.is_negative(), "", &self.data.to_str_radix(10)) diff --git a/src/biguint.rs b/src/biguint.rs index b790c57a..42350714 100644 --- a/src/biguint.rs +++ b/src/biguint.rs @@ -35,7 +35,6 @@ pub(crate) use self::convert::to_str_radix_reversed; pub use self::iter::{U32Digits, U64Digits}; /// A big unsigned integer type. -#[derive(Debug)] pub struct BigUint { data: Vec, } @@ -106,6 +105,12 @@ impl Default for BigUint { } } +impl fmt::Debug for BigUint { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} + impl fmt::Display for BigUint { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad_integral(true, "", &self.to_str_radix(10))