1
1
#[ global_allocator]
2
2
static GLOBAL : mimalloc:: MiMalloc = mimalloc:: MiMalloc ;
3
3
4
+ use std:: borrow:: Cow ;
4
5
use std:: fmt:: Write ;
5
6
use std:: io;
6
7
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -46,7 +47,7 @@ struct WorldRow {
46
47
#[ derive( Serialize ) ]
47
48
pub struct Fortune {
48
49
id : i32 ,
49
- message : String ,
50
+ message : Cow < ' static , str > ,
50
51
}
51
52
52
53
struct PgConnectionPool {
@@ -200,7 +201,7 @@ impl PgConnection {
200
201
fn tell_fortune ( & self ) -> Result < SmallVec < [ Fortune ; 32 ] > , may_postgres:: Error > {
201
202
let mut items: SmallVec < [ _ ; 32 ] > = smallvec:: smallvec![ Fortune {
202
203
id: 0 ,
203
- message: "Additional fortune added at request time." . to_string ( ) ,
204
+ message: Cow :: Borrowed ( "Additional fortune added at request time." ) ,
204
205
} ] ;
205
206
206
207
let rows = self
@@ -211,7 +212,7 @@ impl PgConnection {
211
212
let r = row?;
212
213
items. push ( Fortune {
213
214
id : r. get ( 0 ) ,
214
- message : r. get ( 1 ) ,
215
+ message : Cow :: Owned ( r. get ( 1 ) ) ,
215
216
} ) ;
216
217
}
217
218
@@ -250,7 +251,7 @@ impl HttpService for Techempower {
250
251
let fortunes = self . db . tell_fortune ( ) . unwrap ( ) ;
251
252
let mut body = Vec :: with_capacity ( 2048 ) ;
252
253
ywrite_html ! ( body, "{{> fortune }}" ) ;
253
- rsp. body_mut ( ) . extend_from_slice ( & body) ;
254
+ rsp. body_vec ( body) ;
254
255
}
255
256
p if p. starts_with ( "/queries" ) => {
256
257
rsp. header ( "Content-Type: application/json" ) ;
0 commit comments