Skip to content

Commit

Permalink
Coin uses same output for Debug as Display
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 31, 2023
1 parent 6a5c3bc commit 69edf08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/std/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{fmt, str::FromStr};

use crate::{errors::CoinFromStrError, math::Uint128};

#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)]
pub struct Coin {
pub denom: String,
pub amount: Uint128,
Expand All @@ -19,6 +19,12 @@ impl Coin {
}
}

impl fmt::Debug for Coin {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}{}", self.amount, self.denom)
}
}

impl FromStr for Coin {
type Err = CoinFromStrError;

Expand Down Expand Up @@ -235,4 +241,10 @@ mod tests {
"Invalid amount: number too large to fit in target type"
);
}

#[test]
fn debug_coin() {
let coin = Coin::new(123, "ucosm");
assert_eq!(format!("{:?}", coin), "123ucosm");
}
}

0 comments on commit 69edf08

Please sign in to comment.