Skip to content

Commit 5ef9006

Browse files
refactor: impl Display for Felt via BigUint (#146)
Signed-off-by: Dori Medini <[email protected]>
1 parent 156de10 commit 5ef9006

File tree

1 file changed

+1
-23
lines changed
  • crates/starknet-types-core/src/felt

1 file changed

+1
-23
lines changed

crates/starknet-types-core/src/felt/mod.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -750,29 +750,7 @@ mod formatting {
750750
/// Represents [Felt] in decimal by default.
751751
impl fmt::Display for Felt {
752752
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
753-
if *self == Felt::ZERO {
754-
return write!(f, "0");
755-
}
756-
757-
let mut buf = [0u8; 4 * 20];
758-
let mut i = buf.len() - 1;
759-
let mut current = self.0.representative();
760-
let ten = UnsignedInteger::from(10_u16);
761-
762-
loop {
763-
let (quotient, remainder) = current.div_rem(&ten);
764-
let digit = remainder.limbs[3] as u8;
765-
buf[i] = digit + b'0';
766-
current = quotient;
767-
if current == UnsignedInteger::from(0_u16) {
768-
break;
769-
}
770-
i -= 1;
771-
}
772-
773-
// sequence of `'0'..'9'` chars is guaranteed to be a valid UTF8 string
774-
let s = core::str::from_utf8(&buf[i..]).unwrap();
775-
fmt::Display::fmt(s, f)
753+
write!(f, "{}", self.to_biguint())
776754
}
777755
}
778756

0 commit comments

Comments
 (0)