Skip to content

Commit 05a4c67

Browse files
committed
Merge branch 'master' of https://github.com/David-OConnor/seed
2 parents 220c488 + 0c60cb8 commit 05a4c67

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/dom_types.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,10 @@ impl Attrs {
302302

303303
/// Create an HTML-compatible string representation
304304
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(" ")
310309
}
311310

312311
/// Add a new key, value pair
@@ -355,14 +354,11 @@ impl Style {
355354
/// Output style as a string, as would be set in the DOM as the attribute value
356355
/// for 'style'. Eg: "display: flex; font-size: 1.5em"
357356
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(";")
366362
}
367363

368364
pub fn add(&mut self, key: &str, val: &str) {

0 commit comments

Comments
 (0)