aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock261
-rw-r--r--Cargo.toml6
-rw-r--r--src/main.rs75
3 files changed, 242 insertions, 100 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1c73a0e..9759d76 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -16,10 +16,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
16checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" 16checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
17 17
18[[package]] 18[[package]]
19name = "arc-swap" 19name = "async-channel"
20version = "0.4.7" 20version = "1.4.0"
21source = "registry+https://github.com/rust-lang/crates.io-index"
22checksum = "43de69555a39d52918e2bc33a408d3c0a86c829b212d898f4ca25d21a6387478"
23dependencies = [
24 "concurrent-queue",
25 "event-listener",
26 "futures-core",
27]
28
29[[package]]
30name = "async-executor"
31version = "0.1.2"
21source = "registry+https://github.com/rust-lang/crates.io-index" 32source = "registry+https://github.com/rust-lang/crates.io-index"
22checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" 33checksum = "90f47c78ea98277cb1f5e6f60ba4fc762f5eafe9f6511bc2f7dfd8b75c225650"
34dependencies = [
35 "async-io",
36 "futures-lite",
37 "multitask",
38 "parking 1.0.6",
39 "scoped-tls",
40 "waker-fn",
41]
42
43[[package]]
44name = "async-io"
45version = "0.1.11"
46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "3ae22a338d28c75b53702b66f77979062cb29675db376d99e451af4fa79dedb3"
48dependencies = [
49 "cfg-if",
50 "concurrent-queue",
51 "futures-lite",
52 "libc",
53 "once_cell",
54 "parking 2.0.0",
55 "polling",
56 "socket2",
57 "vec-arena",
58 "wepoll-sys-stjepang",
59 "winapi 0.3.9",
60]
61
62[[package]]
63name = "async-task"
64version = "3.0.0"
65source = "registry+https://github.com/rust-lang/crates.io-index"
66checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3"
67
68[[package]]
69name = "atomic-waker"
70version = "1.0.0"
71source = "registry+https://github.com/rust-lang/crates.io-index"
72checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a"
23 73
24[[package]] 74[[package]]
25name = "autocfg" 75name = "autocfg"
@@ -40,12 +90,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 90checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
41 91
42[[package]] 92[[package]]
93name = "blocking"
94version = "0.5.2"
95source = "registry+https://github.com/rust-lang/crates.io-index"
96checksum = "ea5800d29218fea137b0880387e5948694a23c93fcdde157006966693a865c7c"
97dependencies = [
98 "async-channel",
99 "atomic-waker",
100 "futures-lite",
101 "once_cell",
102 "waker-fn",
103]
104
105[[package]]
43name = "bytes" 106name = "bytes"
44version = "0.5.6" 107version = "0.5.6"
45source = "registry+https://github.com/rust-lang/crates.io-index" 108source = "registry+https://github.com/rust-lang/crates.io-index"
46checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" 109checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38"
47 110
48[[package]] 111[[package]]
112name = "cache-padded"
113version = "1.1.1"
114source = "registry+https://github.com/rust-lang/crates.io-index"
115checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba"
116
117[[package]]
118name = "cc"
119version = "1.0.59"
120source = "registry+https://github.com/rust-lang/crates.io-index"
121checksum = "66120af515773fb005778dc07c261bd201ec8ce50bd6e7144c927753fe013381"
122
123[[package]]
49name = "cfg-if" 124name = "cfg-if"
50version = "0.1.10" 125version = "0.1.10"
51source = "registry+https://github.com/rust-lang/crates.io-index" 126source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -61,6 +136,15 @@ dependencies = [
61] 136]
62 137
63[[package]] 138[[package]]
139name = "concurrent-queue"
140version = "1.2.2"
141source = "registry+https://github.com/rust-lang/crates.io-index"
142checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
143dependencies = [
144 "cache-padded",
145]
146
147[[package]]
64name = "derive_more" 148name = "derive_more"
65version = "0.99.9" 149version = "0.99.9"
66source = "registry+https://github.com/rust-lang/crates.io-index" 150source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -72,6 +156,12 @@ dependencies = [
72] 156]
73 157
74[[package]] 158[[package]]
159name = "easy-parallel"
160version = "3.1.0"
161source = "registry+https://github.com/rust-lang/crates.io-index"
162checksum = "1dd4afd79212583ff429b913ad6605242ed7eec277e950b1438f300748f948f4"
163
164[[package]]
75name = "encoding_rs" 165name = "encoding_rs"
76version = "0.8.23" 166version = "0.8.23"
77source = "registry+https://github.com/rust-lang/crates.io-index" 167source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -81,6 +171,12 @@ dependencies = [
81] 171]
82 172
83[[package]] 173[[package]]
174name = "event-listener"
175version = "2.4.0"
176source = "registry+https://github.com/rust-lang/crates.io-index"
177checksum = "e1cd41440ae7e4734bbd42302f63eaba892afc93a3912dad84006247f0dedb0e"
178
179[[package]]
84name = "fallible-iterator" 180name = "fallible-iterator"
85version = "0.2.0" 181version = "0.2.0"
86source = "registry+https://github.com/rust-lang/crates.io-index" 182source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -93,6 +189,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
93checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" 189checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
94 190
95[[package]] 191[[package]]
192name = "fastrand"
193version = "1.3.4"
194source = "registry+https://github.com/rust-lang/crates.io-index"
195checksum = "4bd3bdaaf0a72155260a1c098989b60db1cbb22d6a628e64f16237aa4da93cc7"
196
197[[package]]
96name = "fnv" 198name = "fnv"
97version = "1.0.7" 199version = "1.0.7"
98source = "registry+https://github.com/rust-lang/crates.io-index" 200source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -169,6 +271,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
169checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" 271checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789"
170 272
171[[package]] 273[[package]]
274name = "futures-lite"
275version = "0.1.11"
276source = "registry+https://github.com/rust-lang/crates.io-index"
277checksum = "97999970129b808f0ccba93211201d431fcc12d7e1ffae03a61b5cedd1a7ced2"
278dependencies = [
279 "fastrand",
280 "futures-core",
281 "futures-io",
282 "memchr",
283 "parking 2.0.0",
284 "pin-project-lite",
285 "waker-fn",
286]
287
288[[package]]
172name = "futures-macro" 289name = "futures-macro"
173version = "0.3.5" 290version = "0.3.5"
174source = "registry+https://github.com/rust-lang/crates.io-index" 291source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -248,12 +365,11 @@ name = "hedge"
248version = "0.1.0" 365version = "0.1.0"
249dependencies = [ 366dependencies = [
250 "anyhow", 367 "anyhow",
251 "futures",
252 "hyper", 368 "hyper",
253 "multer", 369 "multer",
254 "nanoid", 370 "nanoid",
255 "rusqlite", 371 "rusqlite",
256 "tokio", 372 "smol",
257 "url", 373 "url",
258] 374]
259 375
@@ -440,36 +556,13 @@ dependencies = [
440 "kernel32-sys", 556 "kernel32-sys",
441 "libc", 557 "libc",
442 "log", 558 "log",
443 "miow 0.2.1", 559 "miow",
444 "net2", 560 "net2",
445 "slab", 561 "slab",
446 "winapi 0.2.8", 562 "winapi 0.2.8",
447] 563]
448 564
449[[package]] 565[[package]]
450name = "mio-named-pipes"
451version = "0.1.7"
452source = "registry+https://github.com/rust-lang/crates.io-index"
453checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656"
454dependencies = [
455 "log",
456 "mio",
457 "miow 0.3.5",
458 "winapi 0.3.9",
459]
460
461[[package]]
462name = "mio-uds"
463version = "0.6.8"
464source = "registry+https://github.com/rust-lang/crates.io-index"
465checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0"
466dependencies = [
467 "iovec",
468 "libc",
469 "mio",
470]
471
472[[package]]
473name = "miow" 566name = "miow"
474version = "0.2.1" 567version = "0.2.1"
475source = "registry+https://github.com/rust-lang/crates.io-index" 568source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -482,16 +575,6 @@ dependencies = [
482] 575]
483 576
484[[package]] 577[[package]]
485name = "miow"
486version = "0.3.5"
487source = "registry+https://github.com/rust-lang/crates.io-index"
488checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e"
489dependencies = [
490 "socket2",
491 "winapi 0.3.9",
492]
493
494[[package]]
495name = "multer" 578name = "multer"
496version = "1.2.2" 579version = "1.2.2"
497source = "registry+https://github.com/rust-lang/crates.io-index" 580source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -511,6 +594,17 @@ dependencies = [
511] 594]
512 595
513[[package]] 596[[package]]
597name = "multitask"
598version = "0.2.0"
599source = "registry+https://github.com/rust-lang/crates.io-index"
600checksum = "c09c35271e7dcdb5f709779111f2c8e8ab8e06c1b587c1c6a9e179d865aaa5b4"
601dependencies = [
602 "async-task",
603 "concurrent-queue",
604 "fastrand",
605]
606
607[[package]]
514name = "nanoid" 608name = "nanoid"
515version = "0.3.0" 609version = "0.3.0"
516source = "registry+https://github.com/rust-lang/crates.io-index" 610source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -547,6 +641,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
547checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" 641checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"
548 642
549[[package]] 643[[package]]
644name = "parking"
645version = "1.0.6"
646source = "registry+https://github.com/rust-lang/crates.io-index"
647checksum = "6cb300f271742d4a2a66c01b6b2fa0c83dfebd2e0bf11addb879a3547b4ed87c"
648
649[[package]]
650name = "parking"
651version = "2.0.0"
652source = "registry+https://github.com/rust-lang/crates.io-index"
653checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
654
655[[package]]
550name = "percent-encoding" 656name = "percent-encoding"
551version = "2.1.0" 657version = "2.1.0"
552source = "registry+https://github.com/rust-lang/crates.io-index" 658source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -591,6 +697,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
591checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" 697checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
592 698
593[[package]] 699[[package]]
700name = "polling"
701version = "0.1.5"
702source = "registry+https://github.com/rust-lang/crates.io-index"
703checksum = "9e09dffb745feffca5be3dea51c02b7b368c4597ab0219a82acaf9799ab3e0d1"
704dependencies = [
705 "cfg-if",
706 "libc",
707 "wepoll-sys-stjepang",
708 "winapi 0.3.9",
709]
710
711[[package]]
594name = "proc-macro-hack" 712name = "proc-macro-hack"
595version = "0.5.18" 713version = "0.5.18"
596source = "registry+https://github.com/rust-lang/crates.io-index" 714source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -775,14 +893,10 @@ dependencies = [
775] 893]
776 894
777[[package]] 895[[package]]
778name = "signal-hook-registry" 896name = "scoped-tls"
779version = "1.2.1" 897version = "1.0.0"
780source = "registry+https://github.com/rust-lang/crates.io-index" 898source = "registry+https://github.com/rust-lang/crates.io-index"
781checksum = "a3e12110bc539e657a646068aaf5eb5b63af9d0c1f7b29c97113fad80e15f035" 899checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
782dependencies = [
783 "arc-swap",
784 "libc",
785]
786 900
787[[package]] 901[[package]]
788name = "slab" 902name = "slab"
@@ -797,6 +911,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
797checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" 911checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
798 912
799[[package]] 913[[package]]
914name = "smol"
915version = "0.3.3"
916source = "registry+https://github.com/rust-lang/crates.io-index"
917checksum = "67583f4ccc13bbb105a0752058d8ad66c47753d85445952809bcaca891954f83"
918dependencies = [
919 "async-channel",
920 "async-executor",
921 "async-io",
922 "blocking",
923 "cfg-if",
924 "easy-parallel",
925 "futures-lite",
926 "num_cpus",
927 "tokio",
928]
929
930[[package]]
800name = "socket2" 931name = "socket2"
801version = "0.3.12" 932version = "0.3.12"
802source = "registry+https://github.com/rust-lang/crates.io-index" 933source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -855,28 +986,11 @@ dependencies = [
855 "futures-core", 986 "futures-core",
856 "iovec", 987 "iovec",
857 "lazy_static", 988 "lazy_static",
858 "libc",
859 "memchr", 989 "memchr",
860 "mio", 990 "mio",
861 "mio-named-pipes",
862 "mio-uds",
863 "num_cpus", 991 "num_cpus",
864 "pin-project-lite", 992 "pin-project-lite",
865 "signal-hook-registry",
866 "slab", 993 "slab",
867 "tokio-macros",
868 "winapi 0.3.9",
869]
870
871[[package]]
872name = "tokio-macros"
873version = "0.2.5"
874source = "registry+https://github.com/rust-lang/crates.io-index"
875checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
876dependencies = [
877 "proc-macro2",
878 "quote",
879 "syn",
880] 994]
881 995
882[[package]] 996[[package]]
@@ -983,6 +1097,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
983checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" 1097checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c"
984 1098
985[[package]] 1099[[package]]
1100name = "vec-arena"
1101version = "0.5.2"
1102source = "registry+https://github.com/rust-lang/crates.io-index"
1103checksum = "8cb18268690309760d59ee1a9b21132c126ba384f374c59a94db4bc03adeb561"
1104
1105[[package]]
1106name = "waker-fn"
1107version = "1.0.0"
1108source = "registry+https://github.com/rust-lang/crates.io-index"
1109checksum = "9571542c2ce85ce642e6b58b3364da2fb53526360dfb7c211add4f5c23105ff7"
1110
1111[[package]]
986name = "want" 1112name = "want"
987version = "0.3.0" 1113version = "0.3.0"
988source = "registry+https://github.com/rust-lang/crates.io-index" 1114source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -993,6 +1119,15 @@ dependencies = [
993] 1119]
994 1120
995[[package]] 1121[[package]]
1122name = "wepoll-sys-stjepang"
1123version = "1.0.6"
1124source = "registry+https://github.com/rust-lang/crates.io-index"
1125checksum = "6fd319e971980166b53e17b1026812ad66c6b54063be879eb182342b55284694"
1126dependencies = [
1127 "cc",
1128]
1129
1130[[package]]
996name = "winapi" 1131name = "winapi"
997version = "0.2.8" 1132version = "0.2.8"
998source = "registry+https://github.com/rust-lang/crates.io-index" 1133source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index b180b0d..ca60681 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,11 +8,13 @@ edition = "2018"
8 8
9[dependencies] 9[dependencies]
10hyper = "0.13" 10hyper = "0.13"
11tokio = { version = "0.2", features = ["full"] }
12rusqlite = "0.24.0" 11rusqlite = "0.24.0"
13nanoid = "0.3.0" 12nanoid = "0.3.0"
14url = "2.1.1" 13url = "2.1.1"
15anyhow = "1.0" 14anyhow = "1.0"
16futures = "0.3.5"
17multer = "1.2" 15multer = "1.2"
18 16
17
18[dependencies.smol]
19version = "0.3.3"
20features = [ "tokio02" ]
diff --git a/src/main.rs b/src/main.rs
index 769ed03..86af042 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,6 +10,18 @@ use url::form_urlencoded;
10use std::collections::HashMap; 10use std::collections::HashMap;
11use std::path::Path; 11use std::path::Path;
12 12
13fn respond_with_shortlink<S: AsRef<str>>(shortlink: S) -> Response<Body> {
14 Response::builder()
15 .status(StatusCode::OK)
16 .header("content-type", "text/html")
17 .body(Body::from(shortlink.as_ref().to_string()))
18 .unwrap()
19}
20
21fn respond_with_status(s: StatusCode) -> Response<Body> {
22 Response::builder().status(s).body(Body::empty()).unwrap()
23}
24
13fn shorten<S: AsRef<str>>(url: S, conn: &mut Connection) -> Result<String> { 25fn shorten<S: AsRef<str>>(url: S, conn: &mut Connection) -> Result<String> {
14 let mut stmt = conn.prepare("select * from urls where link = ?1")?; 26 let mut stmt = conn.prepare("select * from urls where link = ?1")?;
15 let mut rows = stmt.query(params![url.as_ref().to_string()])?; 27 let mut rows = stmt.query(params![url.as_ref().to_string()])?;
@@ -36,14 +48,22 @@ fn get_link<S: AsRef<str>>(url: S, conn: &mut Connection) -> Result<Option<Strin
36 } 48 }
37} 49}
38 50
39async fn process_multipart(body: Body, boundary: String) -> Result<Response<Body>> { 51async fn process_multipart(
52 body: Body,
53 boundary: String,
54 conn: &mut Connection,
55) -> Result<Response<Body>> {
40 let mut m = Multipart::new(body, boundary); 56 let mut m = Multipart::new(body, boundary);
41 if let Some(field) = m.next_field().await? { 57 if let Some(field) = m.next_field().await? {
42 let content = field 58 if field.name() == Some("shorten") {
43 .text() 59 let content = field
44 .await 60 .text()
45 .with_context(|| format!("Expected field name"))?; 61 .await
46 eprintln!("{}", content); 62 .with_context(|| format!("Expected field name"))?;
63
64 let shortlink = shorten(content, conn)?;
65 return Ok(respond_with_shortlink(shortlink));
66 }
47 } 67 }
48 Ok(Response::builder() 68 Ok(Response::builder()
49 .status(StatusCode::OK) 69 .status(StatusCode::OK)
@@ -61,7 +81,6 @@ async fn shortner_service(req: Request<Body>) -> Result<Response<Body>> {
61 .and_then(|ct| ct.to_str().ok()) 81 .and_then(|ct| ct.to_str().ok())
62 .and_then(|ct| multer::parse_boundary(ct).ok()); 82 .and_then(|ct| multer::parse_boundary(ct).ok());
63 83
64 // Send `BAD_REQUEST` status if the content-type is not multipart/form-data.
65 if boundary.is_none() { 84 if boundary.is_none() {
66 let b = hyper::body::to_bytes(req) 85 let b = hyper::body::to_bytes(req)
67 .await 86 .await
@@ -72,27 +91,14 @@ async fn shortner_service(req: Request<Body>) -> Result<Response<Body>> {
72 .collect::<HashMap<String, String>>(); 91 .collect::<HashMap<String, String>>();
73 92
74 if let Some(n) = params.get("shorten") { 93 if let Some(n) = params.get("shorten") {
75 let shortlink = shorten(n, &mut conn)?; 94 let s = shorten(n, &mut conn)?;
76 eprintln!("{}", shortlink); 95 return Ok(respond_with_shortlink(s));
77 let res = Response::builder()
78 .status(StatusCode::OK)
79 .header("content-type", "text/html")
80 .body(Body::from(shortlink))?;
81 return Ok(res);
82 } else { 96 } else {
83 eprintln!("hello world"); 97 return Ok(respond_with_status(StatusCode::UNPROCESSABLE_ENTITY));
84 let res = Response::builder()
85 .status(StatusCode::UNPROCESSABLE_ENTITY)
86 .body(Body::empty())?;
87 return Ok(res);
88 } 98 }
89 } 99 }
90 100
91 if let Ok(res) = process_multipart(req.into_body(), boundary.unwrap()).await { 101 return process_multipart(req.into_body(), boundary.unwrap(), &mut conn).await;
92 return Ok(res);
93 } else {
94 panic!("nani");
95 }
96 } 102 }
97 &Method::GET => { 103 &Method::GET => {
98 let shortlink = req.uri().path().to_string(); 104 let shortlink = req.uri().path().to_string();
@@ -135,15 +141,14 @@ fn init_db<P: AsRef<Path>>(p: P) -> Result<Connection> {
135 return Ok(conn); 141 return Ok(conn);
136} 142}
137 143
138#[tokio::main] 144fn main() -> Result<()> {
139async fn main() -> Result<()> { 145 smol::run(async {
140 let addr = ([127, 0, 0, 1], 3000).into(); 146 let addr = ([127, 0, 0, 1], 3000).into();
141 147 let service =
142 let service = 148 make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(shortner_service)) });
143 make_service_fn(|_| async { Ok::<_, hyper::Error>(service_fn(shortner_service)) }); 149 let server = Server::bind(&addr).serve(service);
144 150 println!("Listening on http://{}", addr);
145 let server = Server::bind(&addr).serve(service); 151 server.await.unwrap();
146 println!("Listening on http://{}", addr); 152 Ok(())
147 server.await.unwrap(); 153 })
148 Ok(())
149} 154}