Skip to content

Commit 8efd352

Browse files
authored
may-minihttp refine tell_fortune test (rust) (#6541)
1 parent 62d419e commit 8efd352

File tree

1 file changed

+5
-4
lines changed
  • frameworks/Rust/may-minihttp/src

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[global_allocator]
22
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
33

4+
use std::borrow::Cow;
45
use std::fmt::Write;
56
use std::io;
67
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -46,7 +47,7 @@ struct WorldRow {
4647
#[derive(Serialize)]
4748
pub struct Fortune {
4849
id: i32,
49-
message: String,
50+
message: Cow<'static, str>,
5051
}
5152

5253
struct PgConnectionPool {
@@ -200,7 +201,7 @@ impl PgConnection {
200201
fn tell_fortune(&self) -> Result<SmallVec<[Fortune; 32]>, may_postgres::Error> {
201202
let mut items: SmallVec<[_; 32]> = smallvec::smallvec![Fortune {
202203
id: 0,
203-
message: "Additional fortune added at request time.".to_string(),
204+
message: Cow::Borrowed("Additional fortune added at request time."),
204205
}];
205206

206207
let rows = self
@@ -211,7 +212,7 @@ impl PgConnection {
211212
let r = row?;
212213
items.push(Fortune {
213214
id: r.get(0),
214-
message: r.get(1),
215+
message: Cow::Owned(r.get(1)),
215216
});
216217
}
217218

@@ -250,7 +251,7 @@ impl HttpService for Techempower {
250251
let fortunes = self.db.tell_fortune().unwrap();
251252
let mut body = Vec::with_capacity(2048);
252253
ywrite_html!(body, "{{> fortune }}");
253-
rsp.body_mut().extend_from_slice(&body);
254+
rsp.body_vec(body);
254255
}
255256
p if p.starts_with("/queries") => {
256257
rsp.header("Content-Type: application/json");

0 commit comments

Comments
 (0)