Skip to content

Commit 894a8fe

Browse files
ethanfreychipshort
authored andcommitted
Coin uses same output for Debug as Display
1 parent 3333590 commit 894a8fe

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/std/src/coin.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt;
44

55
use crate::math::Uint128;
66

7-
#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, JsonSchema)]
7+
#[derive(Serialize, Deserialize, Clone, Default, PartialEq, Eq, JsonSchema)]
88
pub struct Coin {
99
pub denom: String,
1010
pub amount: Uint128,
@@ -19,6 +19,12 @@ impl Coin {
1919
}
2020
}
2121

22+
impl fmt::Debug for Coin {
23+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
24+
write!(f, "{}{}", self.amount, self.denom)
25+
}
26+
}
27+
2228
impl fmt::Display for Coin {
2329
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2430
// We use the formatting without a space between amount and denom,
@@ -166,4 +172,10 @@ mod tests {
166172
// less than same type
167173
assert!(has_coins(&wallet, &coin(777, "ETH")));
168174
}
175+
176+
#[test]
177+
fn debug_coin() {
178+
let coin = Coin::new(123, "ucosm");
179+
assert_eq!(format!("{:?}", coin), "123ucosm");
180+
}
169181
}

0 commit comments

Comments
 (0)