@@ -303,11 +303,10 @@ impl Attrs {
303
303
}
304
304
305
305
pub fn as_str ( & self ) -> String {
306
- let mut result = String :: new ( ) ;
307
- for ( key, val) in & self . vals {
308
- result += & format ! ( " {k}=\" {v}\" " , k=key, v=val) ;
309
- }
310
- result
306
+ self . vals . iter ( )
307
+ . map ( |( k, v) |format ! ( "{}=\" {}\" " , k, v) )
308
+ . collect :: < Vec < _ > > ( )
309
+ . join ( " " )
311
310
}
312
311
313
312
pub fn add ( & mut self , key : & str , val : & str ) {
@@ -346,14 +345,11 @@ impl Style {
346
345
/// Output style as a string, as would be set in the DOM as the attribute value
347
346
/// for 'style'. Eg: "display: flex; font-size: 1.5em"
348
347
pub fn as_str ( & self ) -> String {
349
- let mut result = String :: new ( ) ;
350
- if self . vals . keys ( ) . len ( ) > 0 {
351
- for ( key, val) in & self . vals {
352
- result += & format ! ( "{k}: {v}; " , k = key, v = val) ;
353
- }
354
- }
355
-
356
- result
348
+ self . vals
349
+ . iter ( )
350
+ . map ( |( k, v) |format ! ( "{}:{};" , k, v) )
351
+ . collect :: < Vec < _ > > ( )
352
+ . join ( ";" )
357
353
}
358
354
359
355
pub fn add ( & mut self , key : & str , val : & str ) {
0 commit comments