Browse Source

:pencil: refine tell fortunes (#8503)

Xudong Huang 1 year ago
parent
commit
56589ef135

+ 1 - 1
frameworks/Rust/may-minihttp/Cargo.toml

@@ -18,7 +18,7 @@ yarte = { version = "0.15", features = ["bytes-buf", "json"] }
 buf-min = { version = "0.7", features = ["bytes"] }
 
 may = { version = "0.3", default-features = false }
-may_minihttp = { git = "https://github.com/Xudong-Huang/may_minihttp.git", rev = "b3080c0", default-features = false }
+may_minihttp = { git = "https://github.com/Xudong-Huang/may_minihttp.git", rev = "f8241e7", default-features = false }
 may_postgres = { git = "https://github.com/Xudong-Huang/may_postgres.git", rev = "bf1d86e", default-features = false }
 
 [profile.release]

+ 3 - 3
frameworks/Rust/may-minihttp/src/main.rs

@@ -198,7 +198,7 @@ impl PgConnection {
         let rows = self.client.query_raw(&self.statement.fortune, &[])?;
 
         let all_rows = Vec::from_iter(rows.map(|r| r.unwrap()));
-        let mut fortunes = Vec::with_capacity(all_rows.capacity() + 1);
+        let mut fortunes = Vec::with_capacity(all_rows.len() + 1);
         fortunes.extend(all_rows.iter().map(|r| Fortune {
             id: r.get(0),
             message: r.get(1),
@@ -209,9 +209,9 @@ impl PgConnection {
         });
         fortunes.sort_by(|it, next| it.message.cmp(next.message));
 
-        let mut body = std::mem::replace(buf, BytesMut::new());
+        let mut body = unsafe { std::ptr::read(buf) };
         ywrite_html!(body, "{{> fortune }}");
-        let _ = std::mem::replace(buf, body);
+        unsafe { std::ptr::write(buf, body) };
         Ok(())
     }
 }