chiark / gitweb /
Reduce String consing in reply userid
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 12:53:20 +0000 (12:53 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 14:26:16 +0000 (14:26 +0000)
Not sure if this is worthwile.  You may want to suppress the lint
clippy::format_collect instead.

src/posting.rs

index 82ba71b2f46b5c3a12aa1ad9879cd7ba1340bab3..f6062e30c3ac7da77e342b2df04ae4df7cb0ff74 100644 (file)
@@ -1,3 +1,4 @@
+use std::fmt::Write as _;
 use std::iter::once;
 use sys_locale::get_locale;
 
@@ -103,7 +104,10 @@ impl Post {
             .chain(st.mentions.iter().map(|m| client.fq(&m.acct)))
             .filter(|acct| acct != &ourself);
 
-        let text = userids.map(|acct| format!("@{} ", acct)).collect();
+        let text = userids.fold(String::new(), |mut s, acct| {
+            write!(s, "@{} ", acct).expect("fmt to string failed");
+            s
+        });
 
         // Set a default content warning of the same as the post we're
         // replying to.