@@ -5,20 +5,18 @@ use std::future::Future;
5
5
use std:: pin:: Pin ;
6
6
use std:: task:: { Context , Poll } ;
7
7
8
- use bytes:: BytesMut ;
9
8
use futures:: future:: ok;
10
9
use ntex:: http:: body:: Body ;
11
10
use ntex:: http:: header:: { HeaderValue , CONTENT_TYPE , SERVER } ;
12
11
use ntex:: http:: { HttpService , KeepAlive , Request , Response , StatusCode } ;
13
12
use ntex:: service:: { Service , ServiceFactory } ;
14
13
use ntex:: web:: Error ;
15
- use simd_json_derive :: Serialize ;
14
+ use yarte :: Serialize ;
16
15
17
16
mod db;
18
17
mod utils;
19
18
20
19
use crate :: db:: PgConnection ;
21
- use crate :: utils:: Writer ;
22
20
23
21
struct App {
24
22
db : PgConnection ,
@@ -77,10 +75,11 @@ impl Service for App {
77
75
78
76
Box :: pin ( async move {
79
77
let worlds = fut. await ?;
80
- let mut body = BytesMut :: with_capacity ( 35 * worlds. len ( ) ) ;
81
- worlds. json_write ( & mut Writer ( & mut body) ) . unwrap ( ) ;
82
- let mut res =
83
- Response :: with_body ( StatusCode :: OK , Body :: Bytes ( body. freeze ( ) ) ) ;
78
+ let size = 35 * worlds. len ( ) ;
79
+ let mut res = Response :: with_body (
80
+ StatusCode :: OK ,
81
+ Body :: Bytes ( worlds. to_bytes ( size) ) ,
82
+ ) ;
84
83
let hdrs = res. headers_mut ( ) ;
85
84
hdrs. insert ( SERVER , h_srv) ;
86
85
hdrs. insert ( CONTENT_TYPE , h_ct) ;
@@ -95,10 +94,11 @@ impl Service for App {
95
94
96
95
Box :: pin ( async move {
97
96
let worlds = fut. await ?;
98
- let mut body = BytesMut :: with_capacity ( 35 * worlds. len ( ) ) ;
99
- worlds. json_write ( & mut Writer ( & mut body) ) . unwrap ( ) ;
100
- let mut res =
101
- Response :: with_body ( StatusCode :: OK , Body :: Bytes ( body. freeze ( ) ) ) ;
97
+ let size = 35 * worlds. len ( ) ;
98
+ let mut res = Response :: with_body (
99
+ StatusCode :: OK ,
100
+ Body :: Bytes ( worlds. to_bytes ( size) ) ,
101
+ ) ;
102
102
let hdrs = res. headers_mut ( ) ;
103
103
hdrs. insert ( SERVER , h_srv) ;
104
104
hdrs. insert ( CONTENT_TYPE , h_ct) ;
0 commit comments