Update to Rust 2021

Also update dependencies and codebase to reflect 2021 standards and changes (tokio tests, etc)
This commit is contained in:
Nick Bland 2022-01-03 18:13:39 +10:00
parent bfcaa6f487
commit fcf0bea45f
No known key found for this signature in database
GPG Key ID: B46CF88E4DAB4A2C
9 changed files with 225 additions and 231 deletions

320
Cargo.lock generated
View File

@ -4,15 +4,16 @@ version = 3
[[package]]
name = "actix-codec"
version = "0.4.0"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d5dbeb2d9e51344cb83ca7cc170f1217f9fe25bfc50160e6e200b5c31c1019a"
checksum = "a36c014a3e811624313b51a227b775ecba55d36ef9462bbaac7d4f13e54c9271"
dependencies = [
"bitflags",
"bytes",
"futures-core",
"futures-sink",
"log",
"memchr",
"pin-project-lite",
"tokio",
"tokio-util",
@ -20,14 +21,13 @@ dependencies = [
[[package]]
name = "actix-http"
version = "3.0.0-beta.11"
version = "3.0.0-beta.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9b510d35f13987537289f38bf136e7e702a5c87cc28760310cc459544f40afd"
checksum = "dac76407e2be239b5e544c9d83bdac4a0d68ae188031ac0424aa3e4868a669be"
dependencies = [
"actix-codec",
"actix-rt",
"actix-service",
"actix-tls",
"actix-utils",
"ahash",
"base64",
@ -39,24 +39,20 @@ dependencies = [
"encoding_rs",
"flate2",
"futures-core",
"futures-util",
"h2",
"http",
"httparse",
"httpdate",
"itoa",
"itoa 1.0.1",
"language-tags",
"local-channel",
"log",
"mime",
"once_cell",
"percent-encoding",
"pin-project",
"pin-project-lite",
"rand",
"sha-1",
"sha-1 0.10.0",
"smallvec",
"tokio",
"zstd",
]
@ -72,23 +68,23 @@ dependencies = [
[[package]]
name = "actix-router"
version = "0.5.0-beta.2"
version = "0.5.0-beta.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36b95ce0d76d1aa2f98b681702807475ade0f99bd4552546a6843a966d42ea3d"
checksum = "ddd9f117b910fbcce6e9f45092ffd4ff017785a346d09e2d4fd049f4e20384f4"
dependencies = [
"bytestring",
"firestorm",
"http",
"log",
"regex",
"serde 1.0.130",
"serde",
]
[[package]]
name = "actix-rt"
version = "2.3.0"
version = "2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea360596a50aa9af459850737f99293e5cb9114ae831118cb6026b3bbc7583ad"
checksum = "82cf33e04d9911b39bfb7be3c01309568b4315895d3358372dce64ed2c2bf32d"
dependencies = [
"actix-macros",
"futures-core",
@ -97,17 +93,19 @@ dependencies = [
[[package]]
name = "actix-server"
version = "2.0.0-beta.6"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7367665785765b066ad16e1086d26a087f696bc7c42b6f93004ced6cfcf1eeca"
checksum = "c9259b4f3cc9ca96d7d91a7da66b7b01c47653a0da5b0ba3f7f45a344480443b"
dependencies = [
"actix-rt",
"actix-service",
"actix-utils",
"futures-core",
"futures-util",
"log",
"mio",
"mio 0.8.0",
"num_cpus",
"socket2",
"tokio",
]
@ -122,23 +120,6 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "actix-tls"
version = "3.0.0-beta.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4af84e13e4600829858a3e68079be710d1ada461431e1e4c5ae663479ea0a3c"
dependencies = [
"actix-codec",
"actix-rt",
"actix-service",
"actix-utils",
"derive_more",
"futures-core",
"http",
"log",
"tokio-util",
]
[[package]]
name = "actix-utils"
version = "3.0.0"
@ -151,9 +132,9 @@ dependencies = [
[[package]]
name = "actix-web"
version = "4.0.0-beta.10"
version = "4.0.0-beta.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a4b9d00991d8da308070a5cea7f1bbaa153a91c3fb5567937d99b9f46d601e"
checksum = "dcc9a3e9642e035fe81cb9f7ef7eb98e7a049452d5d65637aebeab89c1849e4c"
dependencies = [
"actix-codec",
"actix-http",
@ -169,19 +150,18 @@ dependencies = [
"cfg-if",
"cookie",
"derive_more",
"either",
"encoding_rs",
"futures-core",
"futures-util",
"itoa",
"itoa 1.0.1",
"language-tags",
"log",
"mime",
"once_cell",
"paste",
"pin-project",
"pin-project-lite",
"regex",
"serde 1.0.130",
"serde",
"serde_json",
"serde_urlencoded",
"smallvec",
@ -192,9 +172,9 @@ dependencies = [
[[package]]
name = "actix-web-codegen"
version = "0.5.0-beta.5"
version = "0.5.0-beta.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfe80a8828fa88a0420dc8fdd4c16b8207326c917f17701881b063eadc2a8d3b"
checksum = "30a90b7f6c2fde9a1fe3df4da758c2c3c9d620dfa3eae4da0b6925dc0a13444a"
dependencies = [
"actix-router",
"proc-macro2",
@ -249,7 +229,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -285,6 +265,15 @@ dependencies = [
"generic-array",
]
[[package]]
name = "block-buffer"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95"
dependencies = [
"generic-array",
]
[[package]]
name = "brotli-sys"
version = "0.3.2"
@ -355,7 +344,7 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits 0.2.14",
"num-traits",
"time 0.1.43",
"winapi",
]
@ -368,11 +357,7 @@ checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
dependencies = [
"lazy_static",
"nom 5.1.2",
"rust-ini",
"serde 1.0.130",
"serde-hjson",
"serde_json",
"toml",
"serde",
"yaml-rust",
]
@ -478,6 +463,15 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "crypto-common"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0"
dependencies = [
"generic-array",
]
[[package]]
name = "crypto-mac"
version = "0.11.1"
@ -510,6 +504,17 @@ dependencies = [
"generic-array",
]
[[package]]
name = "digest"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b"
dependencies = [
"block-buffer 0.10.0",
"crypto-common",
"generic-array",
]
[[package]]
name = "dirs"
version = "3.0.2"
@ -548,7 +553,7 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
dependencies = [
"serde 1.0.130",
"serde",
]
[[package]]
@ -695,9 +700,9 @@ dependencies = [
[[package]]
name = "h2"
version = "0.3.6"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964"
checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd"
dependencies = [
"bytes",
"fnv",
@ -761,7 +766,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b"
dependencies = [
"crypto-mac",
"digest",
"digest 0.9.0",
]
[[package]]
@ -772,7 +777,7 @@ checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
dependencies = [
"bytes",
"fnv",
"itoa",
"itoa 0.4.8",
]
[[package]]
@ -813,7 +818,7 @@ dependencies = [
"http-body",
"httparse",
"httpdate",
"itoa",
"itoa 0.4.8",
"pin-project-lite",
"socket2",
"tokio",
@ -886,6 +891,12 @@ version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "jobserver"
version = "0.1.24"
@ -981,21 +992,19 @@ dependencies = [
name = "mail_app"
version = "0.1.0"
dependencies = [
"actix-rt",
"actix-web",
"chrono",
"config",
"log",
"once_cell",
"reqwest",
"serde 1.0.130",
"secrecy",
"serde",
"serde-aux",
"sqlx",
"tokio",
"tracing",
"tracing-actix-web",
"tracing-bunyan-formatter",
"tracing-futures",
"tracing-log",
"tracing-subscriber",
"uuid",
@ -1003,9 +1012,9 @@ dependencies = [
[[package]]
name = "matchers"
version = "0.0.1"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata",
]
@ -1022,8 +1031,8 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
dependencies = [
"block-buffer",
"digest",
"block-buffer 0.9.0",
"digest 0.9.0",
"opaque-debug",
]
@ -1068,6 +1077,19 @@ dependencies = [
"winapi",
]
[[package]]
name = "mio"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
"winapi",
]
[[package]]
name = "miow"
version = "0.3.7"
@ -1133,16 +1155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits 0.2.14",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1440,7 +1453,7 @@ dependencies = [
"native-tls",
"percent-encoding",
"pin-project-lite",
"serde 1.0.130",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
@ -1467,12 +1480,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "rust-ini"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
[[package]]
name = "rustc_version"
version = "0.2.3"
@ -1536,6 +1543,16 @@ dependencies = [
"untrusted",
]
[[package]]
name = "secrecy"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e"
dependencies = [
"serde",
"zeroize",
]
[[package]]
name = "security-framework"
version = "2.4.2"
@ -1592,12 +1609,6 @@ dependencies = [
"pest",
]
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.130"
@ -1614,22 +1625,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93abf9799c576f004252b2a05168d58527fb7c54de12e94b4d12fe3475ffad24"
dependencies = [
"chrono",
"serde 1.0.130",
"serde",
"serde_json",
]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
@ -1648,9 +1647,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"indexmap",
"itoa",
"itoa 0.4.8",
"ryu",
"serde 1.0.130",
"serde",
]
[[package]]
@ -1660,9 +1659,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
dependencies = [
"form_urlencoded",
"itoa",
"itoa 0.4.8",
"ryu",
"serde 1.0.130",
"serde",
]
[[package]]
@ -1671,13 +1670,24 @@ version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer",
"block-buffer 0.9.0",
"cfg-if",
"cpufeatures",
"digest",
"digest 0.9.0",
"opaque-debug",
]
[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if",
"cpufeatures",
"digest 0.10.1",
]
[[package]]
name = "sha1"
version = "0.6.0"
@ -1690,10 +1700,10 @@ version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
dependencies = [
"block-buffer",
"block-buffer 0.9.0",
"cfg-if",
"cpufeatures",
"digest",
"digest 0.9.0",
"opaque-debug",
]
@ -1791,7 +1801,7 @@ dependencies = [
"hex",
"hmac",
"indexmap",
"itoa",
"itoa 0.4.8",
"libc",
"log",
"md-5",
@ -1801,9 +1811,9 @@ dependencies = [
"percent-encoding",
"rand",
"rustls",
"serde 1.0.130",
"serde",
"serde_json",
"sha-1",
"sha-1 0.9.8",
"sha2",
"smallvec",
"sqlformat",
@ -1831,7 +1841,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"serde 1.0.130",
"serde",
"serde_json",
"sha2",
"sqlx-core",
@ -1889,7 +1899,7 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde 1.0.130",
"serde",
"serde_derive",
"syn",
]
@ -1903,7 +1913,7 @@ dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde 1.0.130",
"serde",
"serde_derive",
"serde_json",
"sha1",
@ -2017,7 +2027,7 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cde1cf55178e0293453ba2cca0d5f8392a922e52aa958aee9c28ed02becc6d03"
dependencies = [
"itoa",
"itoa 0.4.8",
"libc",
]
@ -2061,23 +2071,34 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.12.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc"
checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"mio 0.7.14",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.0"
@ -2124,15 +2145,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "toml"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde 1.0.130",
]
[[package]]
name = "tower-service"
version = "0.3.1"
@ -2154,9 +2166,9 @@ dependencies = [
[[package]]
name = "tracing-actix-web"
version = "0.4.0-beta.16"
version = "0.5.0-beta.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2c2b77e219084424d5928fc42557bdaa011a8ef00a1c8492adcfc8fb8bb83c6"
checksum = "2f00575e655451448b6ebde455528917498b3e04bdea7616784d807c49dc0491"
dependencies = [
"actix-web",
"pin-project",
@ -2178,15 +2190,15 @@ dependencies = [
[[package]]
name = "tracing-bunyan-formatter"
version = "0.1.7"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06718867c20ea03700d41a9413610cccf5d772caea792f34cc73cdd43f0e14a6"
checksum = "1cb2ad6aa9b1c637d84c54db002275bbf72a7f3c6fed80f8b33f5af0c39027e9"
dependencies = [
"chrono",
"gethostname",
"log",
"serde 1.0.130",
"serde",
"serde_json",
"time 0.3.3",
"tracing",
"tracing-core",
"tracing-log",
@ -2223,36 +2235,22 @@ dependencies = [
"tracing-core",
]
[[package]]
name = "tracing-serde"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b"
dependencies = [
"serde 1.0.130",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.2.25"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71"
checksum = "5d81bfa81424cc98cb034b837c985b7a290f592e5b4322f353f94a0ab0f9f594"
dependencies = [
"ansi_term",
"chrono",
"lazy_static",
"matchers",
"regex",
"serde 1.0.130",
"serde_json",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
"tracing-serde",
]
[[package]]
@ -2507,19 +2505,25 @@ dependencies = [
]
[[package]]
name = "zstd"
version = "0.7.0+zstd.1.4.9"
name = "zeroize"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9428752481d8372e15b1bf779ea518a179ad6c771cca2d2c60e4fbff3cc2cd52"
checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619"
[[package]]
name = "zstd"
version = "0.9.1+zstd.1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "538b8347df9257b7fbce37677ef7535c00a3c7bf1f81023cc328ed7fe4b41de8"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "3.1.0+zstd.1.4.9"
version = "4.1.2+zstd.1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa1926623ad7fe406e090555387daf73db555b948134b4d73eac5eb08fb666d"
checksum = "9fb4cfe2f6e6d35c5d27ecd9d256c4b6f7933c4895654917460ec56c29336cc1"
dependencies = [
"libc",
"zstd-sys",
@ -2527,9 +2531,9 @@ dependencies = [
[[package]]
name = "zstd-sys"
version = "1.5.0+zstd.1.4.9"
version = "1.6.2+zstd.1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e6c094340240369025fc6b731b054ee2a834328fa584310ac96aa4baebdc465"
checksum = "2daf2f248d9ea44454bfcb2516534e8b8ad2fc91bf818a1885495fc42bc8ac9f"
dependencies = [
"cc",
"libc",

View File

@ -1,43 +1,32 @@
[package]
name = "mail_app"
version = "0.1.0"
authors = ["Nick Bland"]
edition = "2018"
authors = ["NickBland <nick.bland@nickbland.dev>"]
edition = "2021"
[lib]
path = "src/lib.rs"
[[bin]]
path = "src/main.rs"
name = "mail_app"
[dependencies]
actix-web = "4.0.0-beta.8"
config = "0.11.0"
serde = { version = "1", features = ["derive"]}
actix-web = "=4.0.0-beta.16"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde = "1.0.115"
config = { version = "0.11", default-features = false, features = ["yaml"] }
sqlx = { version = "0.5.5", default-features = false, features = [ "runtime-actix-rustls", "macros", "postgres", "uuid", "chrono", "migrate", "offline"] }
uuid = { version = "0.8.1", features = ["v4"] }
chrono = "0.4.15"
tracing = "0.1.19"
tracing-futures = "0.2.4"
tracing-subscriber = { version = "0.2.12", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.1.6"
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3.1"
tracing-log = "0.1.1"
tracing-actix-web = "0.4.0-beta.12"
serde-aux = "3.0.1"
log = "0.4"
[dependencies.sqlx]
version = "0.5.7"
default-features = false
features = [
"runtime-actix-rustls",
"macros",
"postgres",
"uuid",
"chrono",
"migrate",
"offline"
]
serde-aux = "3"
tracing-actix-web = "0.5.0-beta.7"
secrecy = { version = "0.8", features = ["serde"] }
[dev-dependencies]
actix-rt = "2"
once_cell = "1.8.0"
reqwest = "0.11"
tokio = "1"
reqwest = { version = "0.11", features = ["json"] }
once_cell = "1.7.2"

View File

@ -2,6 +2,7 @@ use std::convert::{TryFrom, TryInto};
use serde_aux::field_attributes::deserialize_number_from_string;
use sqlx::postgres::{PgConnectOptions, PgSslMode};
use sqlx::ConnectOptions;
#[derive(serde::Deserialize)]
pub struct Settings {
@ -27,6 +28,28 @@ pub struct DatabaseSettings {
pub require_ssl: bool,
}
impl DatabaseSettings {
pub fn without_db(&self) -> PgConnectOptions {
let ssl_mode = if self.require_ssl {
PgSslMode::Require
} else {
PgSslMode::Prefer
};
PgConnectOptions::new()
.host(&self.host)
.username(&self.username)
.password(&self.password)
.port(self.port)
.ssl_mode(ssl_mode)
}
pub fn with_db(&self) -> PgConnectOptions {
let mut options = self.without_db().database(&self.database_name);
options.log_statements(tracing::log::LevelFilter::Trace);
options
}
}
pub fn get_configuration() -> Result<Settings, config::ConfigError> {
// Initialise configuration reader
let mut settings = config::Config::default();
@ -78,23 +101,3 @@ impl TryFrom<String> for Environment {
}
}
}
impl DatabaseSettings {
pub fn without_db(&self) -> PgConnectOptions {
let ssl_mode = if self.require_ssl {
PgSslMode::Require
} else {
PgSslMode::Prefer
};
PgConnectOptions::new()
.host(&self.host)
.username(&self.username)
.password(&self.password)
.port(self.port)
.ssl_mode(ssl_mode)
}
pub fn with_db(&self) -> PgConnectOptions {
self.without_db().database(&self.database_name).log_statements(log::LevelFilter::Trace)
}
}

View File

@ -1,3 +1,4 @@
#![allow(clippy::toplevel_ref_arg)]
pub mod configuration;
pub mod routes;
pub mod startup;

View File

@ -5,7 +5,7 @@ use mail_app::startup::run;
use mail_app::configuration::get_configuration;
use mail_app::telemetry::{get_subscriber, init_subscriber};
#[actix_web::main]
#[tokio::main]
async fn main() -> std::io::Result<()> {
let subscriber = get_subscriber("mail_app".into(), "info".into(), std::io::stdout);
init_subscriber(subscriber);

View File

@ -32,12 +32,10 @@ pub async fn subscribe(form: web::Form<FormData>, pool: web::Data<PgPool>,) -> H
skip(form, pool)
)]
pub async fn insert_subscriber(pool: &PgPool, form: &FormData) -> Result<(), sqlx::Error> {
// _connect uses PgPool from the application state as defined in startup.rs
// Use a match statement for the query as it only returns two outcomes
sqlx::query!(
r#"
INSERT INTO subscriptions (id, email, name, subscribed_at)
VALUES($1, $2, $3, $4)
VALUES ($1, $2, $3, $4)
"#,
Uuid::new_v4(),
form.email,

View File

@ -1,6 +1,6 @@
use actix_web::{web, App, HttpServer};
use actix_web::dev::Server;
// use actix_web::web::Data;
use actix_web::web::Data;
use std::net::TcpListener;
use sqlx::PgPool;
use tracing_actix_web::TracingLogger;
@ -8,13 +8,13 @@ use tracing_actix_web::TracingLogger;
use crate::routes::{health_check, subscribe};
pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
let db_pool = web::Data::new(db_pool); // Wrap connection in a smart pointer
let db_pool = Data::new(db_pool);
let server = HttpServer::new(move || {
App::new()
.wrap(TracingLogger::default())
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
.app_data(db_pool.clone()) // Get pointer copy and attach to application state
.app_data(db_pool.clone())
})
.listen(listener)?
.run();

View File

@ -4,17 +4,16 @@ use tracing_log::LogTracer;
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry, fmt::MakeWriter};
/// Compose multiple layers into a tracing compatible subscriber
pub fn get_subscriber(
pub fn get_subscriber<Sink>(
name: String,
env_filter: String,
sink: impl MakeWriter + Send + Sync + 'static,
) -> impl Subscriber + Sync + Send {
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new(env_filter));
let formatting_layer = BunyanFormattingLayer::new(
name,
sink
);
sink: Sink,
) -> impl Subscriber + Sync + Send
where
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static,
{
let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter));
let formatting_layer = BunyanFormattingLayer::new(name, sink);
Registry::default()
.with(env_filter)
.with(JsonStorageLayer)

View File

@ -49,16 +49,16 @@ async fn spawn_app() -> TestApp {
pub async fn configure_database(config: &DatabaseSettings) -> PgPool {
// Create database
let mut connection = PgConnection::connect(&config.without_db())
let mut connection = PgConnection::connect_with(&config.without_db())
.await
.expect("Failed to connect to Postgres");
connection
.execute(&*format!(r#"CREATE DATABASE "{}";"#, config.database_name).as_str())
.execute(&*format!(r#"CREATE DATABASE "{}";"#, config.database_name))
.await
.expect("Failed to create database.");
// Migrate database
let connection_pool = PgPool::connect(config.with_db())
let connection_pool = PgPool::connect_with(config.with_db())
.await
.expect("Failed to connect to Postgres.");
sqlx::migrate!("./migrations")
@ -69,7 +69,7 @@ pub async fn configure_database(config: &DatabaseSettings) -> PgPool {
connection_pool
}
#[actix_rt::test]
#[tokio::test]
async fn health_check_works() {
// Arrange
let app = spawn_app().await;
@ -87,7 +87,7 @@ async fn health_check_works() {
assert_eq!(Some(0), response.content_length());
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_200_for_valid_form_data() {
// Arrange
let app = spawn_app().await;
@ -115,7 +115,7 @@ async fn subscribe_returns_200_for_valid_form_data() {
assert_eq!(saved.name, "le guin");
}
#[actix_rt::test]
#[tokio::test]
async fn subscribe_returns_400_for_missing_form_data() {
//Arrange
let app = spawn_app().await;