From a25052f57860c2692a1b31021d8468bf4254c174 Mon Sep 17 00:00:00 2001 From: Pass Automated Testing Suite Date: Sun, 17 Oct 2021 12:18:11 +0200 Subject: [PATCH] Add optional axum build configuration and README --- Cargo.lock | 531 ++++++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 10 +- README.md | 17 ++ src/main.rs | 66 ++++++- 4 files changed, 583 insertions(+), 41 deletions(-) create mode 100644 README.md diff --git a/Cargo.lock b/Cargo.lock index 0062f24..1340155 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f2c11af4b06dc935d8e1b1491dad56bfb32febc49096a91e773f8535c176453" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", "tokio-codec", @@ -28,7 +28,7 @@ dependencies = [ "derive_more", "either", "futures", - "http", + "http 0.1.21", "log", "tokio-current-thread", "tokio-tcp", @@ -40,7 +40,11 @@ name = "actix-gcd" version = "0.1.0" dependencies = [ "actix-web", + "axum", + "hyper", "serde", + "tokio", + "tower", ] [[package]] @@ -58,7 +62,7 @@ dependencies = [ "base64", "bitflags", "brotli2", - "bytes", + "bytes 0.4.12", "chrono", "copyless", "derive_more", @@ -67,9 +71,9 @@ dependencies = [ "failure", "flate2", "futures", - "h2", + "h2 0.1.26", "hashbrown 0.6.3", - "http", + "http 0.1.21", "httparse", "indexmap", "language-tags", @@ -81,7 +85,7 @@ dependencies = [ "regex", "serde", "serde_json", - "serde_urlencoded", + "serde_urlencoded 0.6.1", "sha1", "slab", "time", @@ -97,8 +101,8 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23224bb527e204261d0291102cb9b52713084def67d94f7874923baefe04ccf7" dependencies = [ - "bytes", - "http", + "bytes 0.4.12", + "http 0.1.21", "log", "regex", "serde", @@ -131,7 +135,7 @@ dependencies = [ "actix-service", "futures", "log", - "mio", + "mio 0.6.23", "net2", "num_cpus", "slab", @@ -190,7 +194,7 @@ dependencies = [ "lazy_static", "log", "num_cpus", - "parking_lot", + "parking_lot 0.9.0", "threadpool", ] @@ -202,7 +206,7 @@ checksum = "908c3109948f5c37a8b57fd343a37dcad5bb1d90bfd06300ac96b17bbe017b95" dependencies = [ "actix-codec", "actix-service", - "bytes", + "bytes 0.4.12", "either", "futures", "log", @@ -228,7 +232,7 @@ dependencies = [ "actix-utils", "actix-web-codegen", "awc", - "bytes", + "bytes 0.4.12", "derive_more", "encoding_rs", "futures", @@ -236,11 +240,11 @@ dependencies = [ "log", "mime", "net2", - "parking_lot", + "parking_lot 0.9.0", "regex", "serde", "serde_json", - "serde_urlencoded", + "serde_urlencoded 0.6.1", "time", "url 2.2.2", ] @@ -289,6 +293,17 @@ dependencies = [ "memchr", ] +[[package]] +name = "async-trait" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +dependencies = [ + "proc-macro2 1.0.30", + "quote 1.0.10", + "syn 1.0.80", +] + [[package]] name = "autocfg" version = "0.1.7" @@ -311,7 +326,7 @@ dependencies = [ "actix-http", "actix-service", "base64", - "bytes", + "bytes 0.4.12", "derive_more", "futures", "log", @@ -320,10 +335,37 @@ dependencies = [ "rand 0.7.3", "serde", "serde_json", - "serde_urlencoded", + "serde_urlencoded 0.6.1", "tokio-timer", ] +[[package]] +name = "axum" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f08f95a202e827209db1491047aa57c18c8adb4c5efcfcfd4a2da4838ee3a72" +dependencies = [ + "async-trait", + "bitflags", + "bytes 1.1.0", + "futures-util", + "http 0.2.5", + "http-body", + "hyper", + "pin-project-lite", + "regex", + "serde", + "serde_json", + "serde_urlencoded 0.7.0", + "sync_wrapper", + "tokio", + "tokio-util", + "tower", + "tower-http", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.61" @@ -390,6 +432,12 @@ dependencies = [ "iovec", ] +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + [[package]] name = "cc" version = "1.0.71" @@ -609,6 +657,46 @@ version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg 1.0.1", + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "getrandom" version = "0.1.16" @@ -644,10 +732,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" dependencies = [ "byteorder", - "bytes", + "bytes 0.4.12", "fnv", "futures", - "http", + "http 0.1.21", "indexmap", "log", "slab", @@ -655,6 +743,25 @@ dependencies = [ "tokio-io", ] +[[package]] +name = "h2" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" +dependencies = [ + "bytes 1.1.0", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 0.2.5", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.6.3" @@ -697,17 +804,69 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" dependencies = [ - "bytes", + "bytes 0.4.12", + "fnv", + "itoa", +] + +[[package]] +name = "http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +dependencies = [ + "bytes 1.1.0", "fnv", "itoa", ] +[[package]] +name = "http-body" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +dependencies = [ + "bytes 1.1.0", + "http 0.2.5", + "pin-project-lite", +] + [[package]] name = "httparse" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +[[package]] +name = "httpdate" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" + +[[package]] +name = "hyper" +version = "0.14.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +dependencies = [ + "bytes 1.1.0", + "futures-channel", + "futures-core", + "futures-util", + "h2 0.3.6", + "http 0.2.5", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.4.2", + "tokio", + "tower-service", + "tracing", + "want", +] + [[package]] name = "idna" version = "0.1.5" @@ -740,6 +899,15 @@ dependencies = [ "hashbrown 0.11.2", ] +[[package]] +name = "instant" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -755,7 +923,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" dependencies = [ - "socket2", + "socket2 0.3.19", "widestring", "winapi 0.3.9", "winreg", @@ -810,6 +978,15 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "lock_api" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.14" @@ -891,12 +1068,25 @@ dependencies = [ "kernel32-sys", "libc", "log", - "miow", + "miow 0.2.2", "net2", "slab", "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow 0.3.7", + "ntapi", + "winapi 0.3.9", +] + [[package]] name = "mio-uds" version = "0.6.8" @@ -905,7 +1095,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio", + "mio 0.6.23", ] [[package]] @@ -920,6 +1110,15 @@ dependencies = [ "ws2_32-sys", ] +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "net2" version = "0.2.37" @@ -931,6 +1130,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -969,17 +1177,34 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + [[package]] name = "parking_lot" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ - "lock_api", - "parking_lot_core", + "lock_api 0.3.4", + "parking_lot_core 0.6.2", "rustc_version", ] +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api 0.4.5", + "parking_lot_core 0.8.5", +] + [[package]] name = "parking_lot_core" version = "0.6.2" @@ -989,9 +1214,23 @@ dependencies = [ "cfg-if 0.1.10", "cloudabi", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "rustc_version", - "smallvec", + "smallvec 0.6.14", + "winapi 0.3.9", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall 0.2.10", + "smallvec 1.7.0", "winapi 0.3.9", ] @@ -1007,6 +1246,38 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +[[package]] +name = "pin-project" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +dependencies = [ + "proc-macro2 1.0.30", + "quote 1.0.10", + "syn 1.0.80", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "ppv-lite86" version = "0.2.14" @@ -1223,6 +1494,15 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.5.4" @@ -1335,6 +1615,18 @@ dependencies = [ "url 2.2.2", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "sha1" version = "0.6.0" @@ -1365,6 +1657,12 @@ dependencies = [ "maybe-uninit", ] +[[package]] +name = "smallvec" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" + [[package]] name = "socket2" version = "0.3.19" @@ -1376,13 +1674,23 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "string" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" dependencies = [ - "bytes", + "bytes 0.4.12", ] [[package]] @@ -1407,6 +1715,12 @@ dependencies = [ "unicode-xid 0.2.2", ] +[[package]] +name = "sync_wrapper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" + [[package]] name = "synstructure" version = "0.12.6" @@ -1463,13 +1777,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "tokio" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +dependencies = [ + "autocfg 1.0.1", + "bytes 1.1.0", + "libc", + "memchr", + "mio 0.7.14", + "num_cpus", + "once_cell", + "parking_lot 0.11.2", + "pin-project-lite", + "signal-hook-registry", + "tokio-macros", + "winapi 0.3.9", +] + [[package]] name = "tokio-codec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25b2998660ba0e70d18684de5d06b70b70a3a747469af9dea7618cc59e75976b" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "tokio-io", ] @@ -1500,11 +1834,22 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", ] +[[package]] +name = "tokio-macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2dd85aeaba7b68df939bd357c6afb36c87951be9e80bf9c859f2fc3e9fca0fd" +dependencies = [ + "proc-macro2 1.0.30", + "quote 1.0.10", + "syn 1.0.80", +] + [[package]] name = "tokio-reactor" version = "0.1.12" @@ -1515,9 +1860,9 @@ dependencies = [ "futures", "lazy_static", "log", - "mio", + "mio 0.6.23", "num_cpus", - "parking_lot", + "parking_lot 0.9.0", "slab", "tokio-executor", "tokio-io", @@ -1532,7 +1877,7 @@ checksum = "d0c34c6e548f101053321cba3da7cbb87a610b85555884c41b07da2eb91aff12" dependencies = [ "futures", "libc", - "mio", + "mio 0.6.23", "mio-uds", "signal-hook-registry", "tokio-executor", @@ -1557,10 +1902,10 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98df18ed66e3b72e742f185882a9e201892407957e45fbff8da17ae7a7c51f72" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "iovec", - "mio", + "mio 0.6.23", "tokio-io", "tokio-reactor", ] @@ -1583,15 +1928,107 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2a0b10e610b39c38b031a2fcab08e4b82f16ece36504988dcbd81dbba650d82" dependencies = [ - "bytes", + "bytes 0.4.12", "futures", "log", - "mio", + "mio 0.6.23", "tokio-codec", "tokio-io", "tokio-reactor", ] +[[package]] +name = "tokio-util" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" +dependencies = [ + "bytes 1.1.0", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15a6b60cdff0cb039d81d3b37f8bc3d7e53dca09069aae3ef2502ca4834fe30" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b56efe69aa0ad2b5da6b942e57ea9f6fe683b7a314d4ff48662e2c8838de1" +dependencies = [ + "bytes 1.1.0", + "futures-core", + "futures-util", + "http 0.2.5", + "http-body", + "pin-project", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if 1.0.0", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2 1.0.30", + "quote 1.0.10", + "syn 1.0.80", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + [[package]] name = "trust-dns-proto" version = "0.7.4" @@ -1606,8 +2043,8 @@ dependencies = [ "lazy_static", "log", "rand 0.6.5", - "smallvec", - "socket2", + "smallvec 0.6.14", + "socket2 0.3.19", "tokio-executor", "tokio-io", "tokio-reactor", @@ -1631,11 +2068,17 @@ dependencies = [ "log", "lru-cache", "resolv-conf", - "smallvec", + "smallvec 0.6.14", "tokio-executor", "trust-dns-proto", ] +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + [[package]] name = "unicode-bidi" version = "0.3.7" @@ -1686,6 +2129,16 @@ dependencies = [ "percent-encoding 2.1.0", ] +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index a8fe024..9f984f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,13 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "1.0.8" serde = { version = "1.0", features = ["derive"] } + +[target.'cfg(axum)'.dependencies] +axum = "0.2.8" +hyper = { version = "0.14.13", features = ["full"] } +tokio = { version = "1.12.0", features = ["full"] } +tower = "0.4.9" + +[target.'cfg(actix)'.dependencies] +actix-web = "1" diff --git a/README.md b/README.md new file mode 100644 index 0000000..8cfe285 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# GCD Calculator using Actix Web OR axum + +Was built as a learning exercise to create small web apps from different web framework in the same module thanks to the `cfg` macro. +Dependencies are also framework specific. + +## Usage +Run in localhost using: +``` +RUSTFLAGS="--cfg=" cargo run +``` + +## Downsides +You have to prepend the `RUSTFLAGS` env anytime. +Using neovim and rust-analyzer, linting is disabled and it becomes a pain to debug. + +## Credits +The gcd and actix specific functions are based on *Programming Rust, 2nd Edition* by Jim Blandy, Jason Orendorff, Leonora F.S. Tindall diff --git a/src/main.rs b/src/main.rs index ea248c2..dd41841 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,34 @@ +#[cfg(axum)] +use axum::{extract::Form, handler::get, response::Html, Router}; +#[cfg(axum)] +use hyper::StatusCode; +#[cfg(axum)] +use std::net::SocketAddr; + +#[cfg(actix)] use actix_web::{web, App, HttpResponse, HttpServer}; + use serde::Deserialize; -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] struct GcdParameters { n: u64, m: u64, } +#[cfg(axum)] +#[tokio::main] +async fn main() { + let app = Router::new().route("/", get(get_index).post(post_gcd)); + + let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); + axum::Server::bind(&addr) + .serve(app.into_make_service()) + .await + .expect("error running server"); +} + +#[cfg(actix)] fn main() { let server = HttpServer::new(|| { App::new() @@ -21,6 +43,28 @@ fn main() { .expect("error running server"); } +#[cfg(axum)] +async fn get_index() -> Html<&'static str> { + Html( + r#" + + + + GCD Calculator + + +
+ + + +
+ + + "#, + ) +} + +#[cfg(actix)] fn get_index() -> HttpResponse { HttpResponse::Ok().content_type("text/html").body( r#" @@ -34,6 +78,26 @@ fn get_index() -> HttpResponse { ) } +#[cfg(axum)] +async fn post_gcd( + Form(input): Form, +) -> Result, (StatusCode, &'static str)> { + if input.n == 0 || input.m == 0 { + return Err(( + StatusCode::BAD_REQUEST, + "Computing the GCD with zero is boring", + )); + } + let response = format!( + "The greatest common divisor of the numbers {} and {} is {}.", + input.n, + input.m, + gcd(input.n, input.m) + ); + Ok(Html(response)) +} + +#[cfg(actix)] fn post_gcd(form: web::Form) -> HttpResponse { if form.n == 0 || form.m == 0 { return HttpResponse::BadRequest() -- 2.20.1