@@ -21,12 +21,7 @@ impl Felt {
21
21
/// The resulting string is guaranted to be 66 chars long, which is enough to represent `Felt::MAX`:
22
22
/// 2 chars for the `0x` prefix and 64 chars for the padded hexadecimal felt value.
23
23
pub fn to_fixed_hex_string ( & self ) -> alloc:: string:: String {
24
- let hex_str = alloc:: format!( "{self:#x}" ) ;
25
- if hex_str. len ( ) < 66 {
26
- alloc:: format!( "0x{:0>64}" , hex_str. strip_prefix( "0x" ) . unwrap( ) )
27
- } else {
28
- hex_str
29
- }
24
+ alloc:: format!( "{self:#066x}" )
30
25
}
31
26
}
32
27
@@ -35,22 +30,7 @@ impl fmt::LowerHex for Felt {
35
30
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
36
31
let hex = alloc:: string:: ToString :: to_string ( & self . 0 ) ;
37
32
let hex = hex. strip_prefix ( "0x" ) . unwrap ( ) ;
38
-
39
- let width = if f. sign_aware_zero_pad ( ) {
40
- f. width ( ) . unwrap ( ) . min ( 64 )
41
- } else {
42
- 1
43
- } ;
44
- if f. alternate ( ) {
45
- write ! ( f, "0x" ) ?;
46
- }
47
-
48
- if hex. len ( ) < width {
49
- for _ in 0 ..( width - hex. len ( ) ) {
50
- write ! ( f, "0" ) ?;
51
- }
52
- }
53
- write ! ( f, "{}" , hex)
33
+ f. pad_integral ( true , if f. alternate ( ) { "0x" } else { "" } , hex)
54
34
}
55
35
}
56
36
@@ -59,22 +39,7 @@ impl fmt::UpperHex for Felt {
59
39
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
60
40
let hex = alloc:: string:: ToString :: to_string ( & self . 0 ) ;
61
41
let hex = hex. strip_prefix ( "0x" ) . unwrap ( ) . to_uppercase ( ) ;
62
-
63
- let width = if f. sign_aware_zero_pad ( ) {
64
- f. width ( ) . unwrap ( ) . min ( 64 )
65
- } else {
66
- 1
67
- } ;
68
- if f. alternate ( ) {
69
- write ! ( f, "0x" ) ?;
70
- }
71
-
72
- if hex. len ( ) < width {
73
- for _ in 0 ..( width - hex. len ( ) ) {
74
- write ! ( f, "0" ) ?;
75
- }
76
- }
77
- write ! ( f, "{}" , hex)
42
+ f. pad_integral ( true , if f. alternate ( ) { "0x" } else { "" } , & hex)
78
43
}
79
44
}
80
45
0 commit comments