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+ } ;
28use core:: {
39 ffi:: CStr ,
410 fmt:: { self , Debug } ,
@@ -50,14 +56,14 @@ pub enum DataType {
5056impl fmt:: Display for DataType {
5157 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5258 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" ) ,
6167 }
6268 }
6369}
@@ -66,8 +72,8 @@ impl DataType {
6672 pub fn display_labels ( & self , endian : object:: Endianness , bytes : & [ u8 ] ) -> Vec < String > {
6773 let mut strs = Vec :: new ( ) ;
6874 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}" ) )
7177 }
7278 strs
7379 }
@@ -100,31 +106,31 @@ impl DataType {
100106 match self {
101107 DataType :: Int8 => {
102108 let i = i8:: from_ne_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
103- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
109+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
104110
105111 if i < 0 {
106112 strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
107113 }
108114 }
109115 DataType :: Int16 => {
110116 let i = endian. read_i16_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
111- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
117+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
112118
113119 if i < 0 {
114120 strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
115121 }
116122 }
117123 DataType :: Int32 => {
118124 let i = endian. read_i32_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
119- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
125+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
120126
121127 if i < 0 {
122128 strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
123129 }
124130 }
125131 DataType :: Int64 => {
126132 let i = endian. read_i64_bytes ( bytes. try_into ( ) . unwrap ( ) ) ;
127- strs. push ( ( format ! ( "{:#x}" , i ) , None ) ) ;
133+ strs. push ( ( format ! ( "{i :#x}" ) , None ) ) ;
128134
129135 if i < 0 {
130136 strs. push ( ( format ! ( "{:#x}" , ReallySigned ( i) ) , None ) ) ;
@@ -151,16 +157,16 @@ impl DataType {
151157 ) ) ;
152158 }
153159 DataType :: Bytes => {
154- strs. push ( ( format ! ( "{:#?}" , bytes ) , None ) ) ;
160+ strs. push ( ( format ! ( "{bytes :#?}" ) , None ) ) ;
155161 }
156162 DataType :: String => {
157163 if let Ok ( cstr) = CStr :: from_bytes_until_nul ( bytes) {
158- strs. push ( ( format ! ( "{:?}" , cstr ) , None ) ) ;
164+ strs. push ( ( format ! ( "{cstr :?}" ) , None ) ) ;
159165 }
160166 if let Some ( nul_idx) = bytes. iter ( ) . position ( |& c| c == b'\0' ) {
161167 let ( cow, _, had_errors) = SHIFT_JIS . decode ( & bytes[ ..nul_idx] ) ;
162168 if !had_errors {
163- let str = format ! ( "{:?}" , cow ) ;
169+ let str = format ! ( "{cow :?}" ) ;
164170 // Only add the Shift JIS string if it's different from the ASCII string.
165171 if !strs. iter ( ) . any ( |x| x. 0 == str) {
166172 strs. push ( ( str, Some ( "Shift JIS" . into ( ) ) ) ) ;
0 commit comments