@@ -302,11 +302,10 @@ impl Attrs {
302
302
303
303
/// Create an HTML-compatible string representation
304
304
pub fn as_str ( & self ) -> String {
305
- let mut result = String :: new ( ) ;
306
- for ( key, val) in & self . vals {
307
- result += & format ! ( " {k}=\" {v}\" " , k=key, v=val) ;
308
- }
309
- result
305
+ self . vals . iter ( )
306
+ . map ( |( k, v) |format ! ( "{}=\" {}\" " , k, v) )
307
+ . collect :: < Vec < _ > > ( )
308
+ . join ( " " )
310
309
}
311
310
312
311
/// Add a new key, value pair
@@ -355,14 +354,11 @@ impl Style {
355
354
/// Output style as a string, as would be set in the DOM as the attribute value
356
355
/// for 'style'. Eg: "display: flex; font-size: 1.5em"
357
356
pub fn as_str ( & self ) -> String {
358
- let mut result = String :: new ( ) ;
359
- if self . vals . keys ( ) . len ( ) > 0 {
360
- for ( key, val) in & self . vals {
361
- result += & format ! ( "{k}: {v}; " , k = key, v = val) ;
362
- }
363
- }
364
-
365
- result
357
+ self . vals
358
+ . iter ( )
359
+ . map ( |( k, v) |format ! ( "{}:{};" , k, v) )
360
+ . collect :: < Vec < _ > > ( )
361
+ . join ( ";" )
366
362
}
367
363
368
364
pub fn add ( & mut self , key : & str , val : & str ) {
0 commit comments