1
- use alloc:: { borrow:: Cow , boxed:: Box , format, string:: String , vec:: Vec } ;
1
+ use alloc:: {
2
+ borrow:: Cow ,
3
+ boxed:: Box ,
4
+ format,
5
+ string:: { String , ToString } ,
6
+ vec:: Vec ,
7
+ } ;
2
8
use core:: {
3
9
ffi:: CStr ,
4
10
fmt:: { self , Debug } ,
@@ -50,14 +56,14 @@ pub enum DataType {
50
56
impl fmt:: Display for DataType {
51
57
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
52
58
match self {
53
- DataType :: Int8 => write ! ( f , "Int8" ) ,
54
- DataType :: Int16 => write ! ( f , "Int16" ) ,
55
- DataType :: Int32 => write ! ( f , "Int32" ) ,
56
- DataType :: Int64 => write ! ( f , "Int64" ) ,
57
- DataType :: Float => write ! ( f , "Float" ) ,
58
- DataType :: Double => write ! ( f , "Double" ) ,
59
- DataType :: Bytes => write ! ( f , "Bytes" ) ,
60
- DataType :: String => write ! ( f , "String" ) ,
59
+ DataType :: Int8 => f . write_str ( "Int8" ) ,
60
+ DataType :: Int16 => f . write_str ( "Int16" ) ,
61
+ DataType :: Int32 => f . write_str ( "Int32" ) ,
62
+ DataType :: Int64 => f . write_str ( "Int64" ) ,
63
+ DataType :: Float => f . write_str ( "Float" ) ,
64
+ DataType :: Double => f . write_str ( "Double" ) ,
65
+ DataType :: Bytes => f . write_str ( "Bytes" ) ,
66
+ DataType :: String => f . write_str ( "String" ) ,
61
67
}
62
68
}
63
69
}
@@ -66,8 +72,8 @@ impl DataType {
66
72
pub fn display_labels ( & self , endian : object:: Endianness , bytes : & [ u8 ] ) -> Vec < String > {
67
73
let mut strs = Vec :: new ( ) ;
68
74
for ( literal, label_override) in self . display_literals ( endian, bytes) {
69
- let label = label_override. unwrap_or_else ( || format ! ( "{}" , self ) ) ;
70
- strs. push ( format ! ( "{}: {}" , label , literal ) )
75
+ let label = label_override. unwrap_or_else ( || self . to_string ( ) ) ;
76
+ strs. push ( format ! ( "{label }: {literal}" ) )
71
77
}
72
78
strs
73
79
}
@@ -100,31 +106,31 @@ impl DataType {
100
106
match self {
101
107
DataType :: Int8 => {
102
108
let i = i8:: from_ne_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
103
- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
109
+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
104
110
105
111
if i < 0 {
106
112
strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
107
113
}
108
114
}
109
115
DataType :: Int16 => {
110
116
let i = endian. read_i16_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
111
- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
117
+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
112
118
113
119
if i < 0 {
114
120
strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
115
121
}
116
122
}
117
123
DataType :: Int32 => {
118
124
let i = endian. read_i32_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
119
- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
125
+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
120
126
121
127
if i < 0 {
122
128
strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
123
129
}
124
130
}
125
131
DataType :: Int64 => {
126
132
let i = endian. read_i64_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
127
- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
133
+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
128
134
129
135
if i < 0 {
130
136
strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
@@ -151,16 +157,16 @@ impl DataType {
151
157
) ) ;
152
158
}
153
159
DataType :: Bytes => {
154
- strs. push ( ( format ! ( "{:#?}" , bytes ) , None ) ) ;
160
+ strs. push ( ( format ! ( "{bytes :#?}" ) , None ) ) ;
155
161
}
156
162
DataType :: String => {
157
163
if let Ok ( cstr) = CStr :: from_bytes_until_nul ( bytes) {
158
- strs. push ( ( format ! ( "{:?}" , cstr ) , None ) ) ;
164
+ strs. push ( ( format ! ( "{cstr :?}" ) , None ) ) ;
159
165
}
160
166
if let Some ( nul_idx) = bytes. iter ( ) . position ( |& c| c == b'\0' ) {
161
167
let ( cow, _, had_errors) = SHIFT_JIS . decode ( & bytes[ ..nul_idx] ) ;
162
168
if !had_errors {
163
- let str = format ! ( "{:?}" , cow ) ;
169
+ let str = format ! ( "{cow :?}" ) ;
164
170
// Only add the Shift JIS string if it's different from the ASCII string.
165
171
if !strs. iter ( ) . any ( |x| x. 0 == str) {
166
172
strs. push ( ( str, Some ( "Shift JIS" . into ( ) ) ) ) ;
0 commit comments