@@ -152,6 +152,8 @@ where
152152
153153impl Display for ValueKind {
154154 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
155+ use std:: fmt:: Write ;
156+
155157 match * self {
156158 Self :: String ( ref value) => write ! ( f, "{}" , value) ,
157159 Self :: Boolean ( value) => write ! ( f, "{}" , value) ,
@@ -161,15 +163,20 @@ impl Display for ValueKind {
161163 Self :: U128 ( value) => write ! ( f, "{}" , value) ,
162164 Self :: Float ( value) => write ! ( f, "{}" , value) ,
163165 Self :: Nil => write ! ( f, "nil" ) ,
164- Self :: Table ( ref table) => write ! ( f, "{{ {} }}" , {
165- table
166- . iter( )
167- . map( |( k, v) | format!( "{} => {}, " , k, v) )
168- . collect:: <String >( )
169- } ) ,
170- Self :: Array ( ref array) => write ! ( f, "{:?}" , {
171- array. iter( ) . map( |e| format!( "{}, " , e) ) . collect:: <String >( )
172- } ) ,
166+ Self :: Table ( ref table) => {
167+ let mut s = String :: new ( ) ;
168+ for ( k, v) in table. iter ( ) {
169+ write ! ( s, "{} => {}, " , k, v) ?
170+ }
171+ write ! ( f, "{{ {s} }}" )
172+ }
173+ Self :: Array ( ref array) => {
174+ let mut s = String :: new ( ) ;
175+ for e in array. iter ( ) {
176+ write ! ( s, "{}, " , e) ?;
177+ }
178+ write ! ( f, "{s:?}" )
179+ }
173180 }
174181 }
175182}
0 commit comments