|
@@ -11,7 +11,6 @@ use serde::Serialize;
|
|
|
|
|
|
mod server;
|
|
|
|
|
|
-static HELLO_WORLD: &'static [u8] = b"Hello, world!";
|
|
|
#[derive(Serialize)]
|
|
|
pub struct Message {
|
|
|
pub message: &'static str,
|
|
@@ -21,7 +20,10 @@ pub struct Message {
|
|
|
fn json(res: &mut Response) {
|
|
|
let headers = res.headers_mut();
|
|
|
headers.insert(header::SERVER, HeaderValue::from_static("S"));
|
|
|
- headers.insert(header::CONTENT_TYPE, HeaderValue::from_static("application/json"));
|
|
|
+ headers.insert(
|
|
|
+ header::CONTENT_TYPE,
|
|
|
+ HeaderValue::from_static("application/json"),
|
|
|
+ );
|
|
|
let data = serde_json::to_vec(&Message {
|
|
|
message: "Hello, World!",
|
|
|
})
|
|
@@ -34,7 +36,7 @@ fn plaintext(res: &mut Response) {
|
|
|
let headers = res.headers_mut();
|
|
|
headers.insert(header::SERVER, HeaderValue::from_static("S"));
|
|
|
headers.insert(header::CONTENT_TYPE, HeaderValue::from_static("text/plain"));
|
|
|
- res.set_body(Body::Once(Bytes::from_static(HELLO_WORLD)));
|
|
|
+ res.set_body(Body::Once(Bytes::from_static(b"Hello, world!")));
|
|
|
}
|
|
|
|
|
|
#[tokio::main]
|
|
@@ -45,15 +47,6 @@ async fn main() {
|
|
|
.push(Router::with_path("json").get(json)),
|
|
|
);
|
|
|
|
|
|
- println!("Started http server: 127.0.0.1:8080");
|
|
|
- let rt = tokio::runtime::Builder::new_current_thread()
|
|
|
- .enable_all()
|
|
|
- .build()
|
|
|
- .unwrap();
|
|
|
- serve(router).await;
|
|
|
-}
|
|
|
-#[inline]
|
|
|
-async fn serve(router: Arc<Router>) {
|
|
|
server::builder()
|
|
|
.http1_pipeline_flush(true)
|
|
|
.serve(Service::new(router))
|