Skip to content

Commit

Permalink
Change Debug to match Display
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cuviper committed Feb 25, 2021
1 parent 72810a5 commit 8f30944
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/bigint.rs
Expand Up @@ -59,7 +59,6 @@ impl Neg for Sign {
}

/// A big signed integer type.
#[derive(Debug)]
pub struct BigInt {
sign: Sign,
data: BigUint,
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion src/biguint.rs
Expand Up @@ -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<BigDigit>,
}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 8f30944

Please sign in to comment.