From 49e29a5751f006a2a761ccba902ea44773cb7df3 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 12 Sep 2020 16:49:45 +0100 Subject: [PATCH] v3 examples (#364) --- .gitignore | 6 ++---- async_data_factory/Cargo.toml | 9 +++------ async_data_factory/src/main.rs | 3 ++- async_db/Cargo.toml | 7 ++----- async_db/src/main.rs | 2 +- async_ex1/Cargo.toml | 5 +---- async_ex1/src/main.rs | 2 +- async_ex2/Cargo.toml | 6 ++++-- async_ex2/src/bin/main.rs | 2 +- async_pg/Cargo.toml | 4 +--- async_pg/src/main.rs | 2 +- awc_https/Cargo.toml | 5 +---- awc_https/src/main.rs | 4 ++-- basics/Cargo.toml | 13 ++++--------- basics/src/main.rs | 22 ++++++++++------------ casbin/Cargo.toml | 4 +--- casbin/src/main.rs | 2 +- cookie-auth/Cargo.toml | 8 +++----- cookie-auth/src/main.rs | 2 +- cookie-session/Cargo.toml | 9 ++------- cookie-session/src/main.rs | 2 +- diesel/Cargo.toml | 6 +----- diesel/src/main.rs | 2 +- docker_sample/Cargo.toml | 5 +---- docker_sample/src/main.rs | 2 +- error_handling/.gitignore | 2 -- error_handling/Cargo.toml | 5 +---- error_handling/src/main.rs | 2 +- form/Cargo.toml | 9 +++++---- form/src/main.rs | 2 +- hello-world/Cargo.toml | 6 ++++-- hello-world/src/main.rs | 2 +- http-proxy/Cargo.toml | 5 +---- http-proxy/src/main.rs | 2 +- json/Cargo.toml | 10 ++++------ json/src/main.rs | 7 +++---- json_decode_error/Cargo.toml | 7 ++----- json_decode_error/src/main.rs | 2 +- json_error/Cargo.toml | 4 +--- json_error/src/main.rs | 2 +- jsonrpc/Cargo.toml | 4 +--- jsonrpc/src/main.rs | 5 ++--- juniper-advanced/Cargo.toml | 4 +--- juniper-advanced/src/main.rs | 2 +- juniper/Cargo.toml | 3 +-- juniper/src/main.rs | 2 +- middleware/Cargo.toml | 9 ++++----- middleware/README.md | 2 +- middleware/src/main.rs | 2 +- middleware/src/read_request_body.rs | 2 +- middleware/src/read_response_body.rs | 20 ++++++++++++++------ multipart-async-std/Cargo.toml | 5 ++--- multipart-async-std/src/main.rs | 2 +- multipart-s3/Cargo.toml | 5 ++--- multipart-s3/src/main.rs | 2 +- multipart/Cargo.toml | 5 ++--- multipart/src/main.rs | 4 +++- openssl/Cargo.toml | 4 +--- openssl/src/main.rs | 2 +- protobuf/Cargo.toml | 8 +++----- protobuf/src/main.rs | 3 ++- r2d2/Cargo.toml | 4 +--- r2d2/src/main.rs | 2 +- redis-session/Cargo.toml | 20 +++++++++++--------- redis-session/src/main.rs | 6 ++++-- redis/Cargo.toml | 13 ++++++------- redis/src/main.rs | 9 +++------ run-in-thread/Cargo.toml | 3 +-- run-in-thread/src/main.rs | 7 +++---- rustls/Cargo.toml | 8 +++----- rustls/src/main.rs | 2 +- server-sent-events/Cargo.toml | 6 ++---- server-sent-events/benchmark.js | 2 +- server-sent-events/src/main.rs | 7 +++---- shutdown-server/Cargo.toml | 5 ++--- shutdown-server/src/main.rs | 2 +- simple-auth-server/Cargo.toml | 11 ++++++----- simple-auth-server/src/main.rs | 5 +++-- sqlx_todo/Cargo.toml | 6 ++---- sqlx_todo/src/main.rs | 4 ++-- state/Cargo.toml | 4 +--- state/src/main.rs | 2 +- static_index/Cargo.toml | 8 ++------ static_index/src/main.rs | 2 +- template_askama/Cargo.toml | 3 +-- template_askama/src/main.rs | 2 +- template_handlebars/Cargo.toml | 5 ++--- template_handlebars/src/main.rs | 2 +- template_tera/Cargo.toml | 6 ++---- template_tera/src/main.rs | 2 +- template_yarte/Cargo.toml | 10 ++++------ template_yarte/src/main.rs | 2 +- todo/Cargo.toml | 8 ++++---- todo/src/main.rs | 2 +- udp-echo/Cargo.toml | 2 +- unix-socket/Cargo.toml | 4 +--- unix-socket/src/main.rs | 2 +- web-cors/backend/.gitignore | 4 ---- web-cors/backend/Cargo.toml | 6 +++--- web-cors/backend/src/main.rs | 2 +- websocket-autobahn/Cargo.toml | 7 +++---- websocket-autobahn/src/main.rs | 2 +- websocket-chat-broker/Cargo.toml | 8 ++++---- websocket-chat/Cargo.toml | 19 +++++++++---------- websocket-chat/src/main.rs | 2 +- websocket-tcp-chat/Cargo.toml | 13 ++++++------- websocket-tcp-chat/src/client.rs | 8 ++++++-- websocket-tcp-chat/src/codec.rs | 6 ++---- websocket-tcp-chat/src/main.rs | 2 +- websocket-tcp-chat/src/session.rs | 6 +++--- websocket/Cargo.toml | 13 ++++++------- websocket/src/main.rs | 2 +- 112 files changed, 251 insertions(+), 333 deletions(-) delete mode 100644 error_handling/.gitignore delete mode 100644 web-cors/backend/.gitignore diff --git a/.gitignore b/.gitignore index b153e47..8ccf3b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,10 @@ # Generated by Cargo # will have compiled files and executables -/*/target/ -target/ +**/target # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock -/*/Cargo.lock -Cargo.lock +**/Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk diff --git a/async_data_factory/Cargo.toml b/async_data_factory/Cargo.toml index 47f6d73..f1b9131 100644 --- a/async_data_factory/Cargo.toml +++ b/async_data_factory/Cargo.toml @@ -3,13 +3,10 @@ name = "async_data_factory" version = "0.1.0" authors = ["fakeshadow <24548779@qq.com>"] edition = "2018" -workspace = ".." - [dependencies] -actix-rt = "1.1.1" -actix-web = { version = "2.0.0" } -num_cpus = "1.13.0" +actix-web = "3" +num_cpus = "1.13" redis = { version = "0.16.0", default-features = false, features = ["tokio-rt-core"] } # redis_tang is an redis pool for test purpose -redis_tang = "0.1.0" +redis_tang = "0.1" diff --git a/async_data_factory/src/main.rs b/async_data_factory/src/main.rs index 007af70..0dcae4d 100644 --- a/async_data_factory/src/main.rs +++ b/async_data_factory/src/main.rs @@ -3,7 +3,7 @@ use actix_web::{get, App, HttpServer}; use redis_tang::{Builder, Pool, RedisManager}; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { let redis_url = std::env::var("REDIS_URL").unwrap_or_else(|_| String::from("redis://127.0.0.1")); @@ -14,6 +14,7 @@ async fn main() -> std::io::Result<()> { let pool = pool_builder(num_cpus, redis_url.as_str()) .await .expect("fail to build pool"); + let pool = RedisWrapper(pool); HttpServer::new(move || { diff --git a/async_db/Cargo.toml b/async_db/Cargo.toml index c1b7598..a632bff 100644 --- a/async_db/Cargo.toml +++ b/async_db/Cargo.toml @@ -3,16 +3,13 @@ name = "async_db" version = "2.0.0" authors = ["Darin Gordon "] edition = "2018" -workspace = ".." [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" - +actix-web = "3" env_logger = "0.7" failure = "0.1.7" futures = "0.3.1" -num_cpus = "1.10.0" +num_cpus = "1.13" r2d2 = "0.8.2" r2d2_sqlite = "0.14" rusqlite = "0.21" diff --git a/async_db/src/main.rs b/async_db/src/main.rs index 66f368f..a5e95c0 100644 --- a/async_db/src/main.rs +++ b/async_db/src/main.rs @@ -48,7 +48,7 @@ async fn parallel_weather(db: web::Data) -> Result Ok(HttpResponse::Ok().json(result.map_err(AWError::from)?)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/async_ex1/Cargo.toml b/async_ex1/Cargo.toml index d98a07c..44d9653 100644 --- a/async_ex1/Cargo.toml +++ b/async_ex1/Cargo.toml @@ -3,12 +3,9 @@ name = "awc_examples" version = "2.0.0" authors = ["dowwie "] edition = "2018" -workspace = ".." [dependencies] -actix-rt = "1.0.0" -actix-web = { version="2.0.0", features=["openssl"] } - +actix-web = { version = "3", features = ["openssl"] } env_logger = "0.7" futures = "0.3.1" serde = { version = "1.0.43", features = ["derive"] } diff --git a/async_ex1/src/main.rs b/async_ex1/src/main.rs index 44c83b7..ab72bcd 100644 --- a/async_ex1/src/main.rs +++ b/async_ex1/src/main.rs @@ -80,7 +80,7 @@ async fn create_something( .body(serde_json::to_string(&d).unwrap())) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/async_ex2/Cargo.toml b/async_ex2/Cargo.toml index 7c35bad..421b17f 100644 --- a/async_ex2/Cargo.toml +++ b/async_ex2/Cargo.toml @@ -5,8 +5,7 @@ authors = ["dowwie "] edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = { version="2.0.0", features = ["openssl"] } +actix-web = { version = "3", features = ["openssl"] } actix-service = "1.0.0" bytes = "0.5.3" env_logger = "0.7" @@ -14,3 +13,6 @@ futures = "0.3.1" serde = { version = "^1.0", features = ["derive"] } serde_json = "1.0.39" time = "0.1.42" + +[dev-dependencies] +actix-rt = "1" diff --git a/async_ex2/src/bin/main.rs b/async_ex2/src/bin/main.rs index 03c7dfc..9eb12ff 100644 --- a/async_ex2/src/bin/main.rs +++ b/async_ex2/src/bin/main.rs @@ -2,7 +2,7 @@ use actix_web::{middleware, App, HttpServer}; use async_ex2::appconfig::config_app; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); env_logger::init(); diff --git a/async_pg/Cargo.toml b/async_pg/Cargo.toml index 9ea1767..535114f 100644 --- a/async_pg/Cargo.toml +++ b/async_pg/Cargo.toml @@ -3,11 +3,9 @@ name = "async_pg" version = "0.1.0" authors = ["dowwie "] edition = "2018" -workspace = ".." [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-web = "3" config = "0.10.1" deadpool-postgres = "0.5.0" derive_more = "0.99.2" diff --git a/async_pg/src/main.rs b/async_pg/src/main.rs index 19f4f21..fd1e089 100644 --- a/async_pg/src/main.rs +++ b/async_pg/src/main.rs @@ -111,7 +111,7 @@ use dotenv::dotenv; use handlers::add_user; use tokio_postgres::NoTls; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { dotenv().ok(); diff --git a/awc_https/Cargo.toml b/awc_https/Cargo.toml index 892a03a..fb38828 100644 --- a/awc_https/Cargo.toml +++ b/awc_https/Cargo.toml @@ -3,10 +3,7 @@ name = "awc_https" version = "0.1.0" authors = ["dowwie "] edition = "2018" -workspace = ".." - [dependencies] -actix-rt = "1.0.0" -actix-web = { version = "2.0.0", features = ["openssl"] } +actix-web = { version = "3", features = ["openssl"] } openssl = "0.10.28" diff --git a/awc_https/src/main.rs b/awc_https/src/main.rs index 5b3d183..c4da375 100644 --- a/awc_https/src/main.rs +++ b/awc_https/src/main.rs @@ -7,7 +7,7 @@ use openssl::ssl::{SslConnector, SslMethod}; async fn index(_req: HttpRequest) -> HttpResponse { let builder = SslConnector::builder(SslMethod::tls()).unwrap(); - let client = Client::build() + let client = Client::builder() .connector(Connector::new().ssl(builder.build()).finish()) .finish(); @@ -31,7 +31,7 @@ async fn index(_req: HttpRequest) -> HttpResponse { HttpResponse::Ok().content_type("image/jpeg").body(payload) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { let port = 3000; diff --git a/basics/Cargo.toml b/basics/Cargo.toml index be3246a..1c69ecd 100644 --- a/basics/Cargo.toml +++ b/basics/Cargo.toml @@ -2,16 +2,11 @@ name = "basics" version = "2.0.0" authors = ["Nikolay Kim "] -workspace = ".." edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" -actix-files = "0.2.1" -actix-session = "0.3.0" -actix-utils = "1.0.3" - -futures = "0.3.1" +actix-web = "3" +actix-files = "0.3" +actix-session = "0.4" +actix-utils = "2" env_logger = "0.7" -bytes = "0.5" diff --git a/basics/src/main.rs b/basics/src/main.rs index 2fee54f..aa91b75 100644 --- a/basics/src/main.rs +++ b/basics/src/main.rs @@ -1,17 +1,12 @@ -#[macro_use] -extern crate actix_web; - -use std::{env, io}; - use actix_files as fs; use actix_session::{CookieSession, Session}; use actix_utils::mpsc; use actix_web::http::{header, Method, StatusCode}; use actix_web::{ - error, guard, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, - Result, + error, get, guard, middleware, web, App, Error, HttpRequest, HttpResponse, + HttpServer, Result, }; -use bytes::Bytes; +use std::{env, io}; /// favicon handler #[get("/favicon")] @@ -50,21 +45,24 @@ async fn response_body(path: web::Path) -> HttpResponse { let text = format!("Hello {}!", *path); let (tx, rx_body) = mpsc::channel(); - let _ = tx.send(Ok::<_, Error>(Bytes::from(text))); + let _ = tx.send(Ok::<_, Error>(web::Bytes::from(text))); HttpResponse::Ok().streaming(rx_body) } /// handler with path parameters like `/user/{name}/` -async fn with_param(req: HttpRequest, path: web::Path<(String,)>) -> HttpResponse { +async fn with_param( + req: HttpRequest, + web::Path((name,)): web::Path<(String,)>, +) -> HttpResponse { println!("{:?}", req); HttpResponse::Ok() .content_type("text/plain") - .body(format!("Hello {}!", path.0)) + .body(format!("Hello {}!", name)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { env::set_var("RUST_LOG", "actix_web=debug,actix_server=info"); env_logger::init(); diff --git a/casbin/Cargo.toml b/casbin/Cargo.toml index d35661f..66cdd22 100644 --- a/casbin/Cargo.toml +++ b/casbin/Cargo.toml @@ -3,10 +3,8 @@ name = "actix-casbin-example" version = "0.1.0" authors = ["Chojan Shang "] edition = "2018" -workspace = ".." [dependencies] -actix-web = "2.0" -actix-rt = "1.1.0" +actix-web = "3" casbin = "0.6.0" loge = {version = "0.4", default-features = false, features = ["colored", "chrono"]} diff --git a/casbin/src/main.rs b/casbin/src/main.rs index 2394ffa..4d7b8da 100644 --- a/casbin/src/main.rs +++ b/casbin/src/main.rs @@ -24,7 +24,7 @@ async fn fail(enforcer: web::Data>, req: HttpRequest) -> HttpRe HttpResponse::Ok().body("Fail: alice is not data1_admin.") // In fact, it can't be displayed. } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "info"); std::env::set_var("LOGE_FORMAT", "target"); diff --git a/cookie-auth/Cargo.toml b/cookie-auth/Cargo.toml index 3795ea0..f2787e5 100644 --- a/cookie-auth/Cargo.toml +++ b/cookie-auth/Cargo.toml @@ -3,11 +3,9 @@ name = "cookie-auth" version = "2.0.0" authors = ["Nikolay Kim "] edition = "2018" -workspace = ".." [dependencies] -actix-web = "2.0.0" -actix-identity = "0.2.0" -actix-rt = "1.0.0" +actix-web = "3" +actix-identity = "0.3" env_logger = "0.7" -rand = "0.7.3" +rand = "0.7" diff --git a/cookie-auth/src/main.rs b/cookie-auth/src/main.rs index 9657bc8..11ce5b7 100644 --- a/cookie-auth/src/main.rs +++ b/cookie-auth/src/main.rs @@ -20,7 +20,7 @@ async fn logout(id: Identity) -> HttpResponse { HttpResponse::Found().header("location", "/").finish() } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/cookie-session/Cargo.toml b/cookie-session/Cargo.toml index 778df8b..ed9a99a 100644 --- a/cookie-session/Cargo.toml +++ b/cookie-session/Cargo.toml @@ -2,14 +2,9 @@ name = "cookie-session" version = "1.0.0" authors = ["Nikolay Kim "] -workspace = ".." edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-session = "0.3.0" -actix-rt = "1.0.0" - -futures = "0.3.1" -time = "0.1" +actix-web = "3" +actix-session = "0.4" env_logger = "0.7" diff --git a/cookie-session/src/main.rs b/cookie-session/src/main.rs index 52b2067..feed64b 100644 --- a/cookie-session/src/main.rs +++ b/cookie-session/src/main.rs @@ -25,7 +25,7 @@ async fn index(session: Session, req: HttpRequest) -> Result<&'static str> { Ok("welcome!") } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/diesel/Cargo.toml b/diesel/Cargo.toml index c468289..9ced2d4 100644 --- a/diesel/Cargo.toml +++ b/diesel/Cargo.toml @@ -5,14 +5,10 @@ authors = [ "Nikolay Kim ", "Rob Ede ", ] -workspace = ".." edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" - -bytes = "0.5" +actix-web = "3" diesel = { version = "^1.1.0", features = ["sqlite", "r2d2"] } dotenv = "0.15" env_logger = "0.7" diff --git a/diesel/src/main.rs b/diesel/src/main.rs index 83026d5..e4f81ae 100644 --- a/diesel/src/main.rs +++ b/diesel/src/main.rs @@ -62,7 +62,7 @@ async fn add_user( Ok(HttpResponse::Ok().json(user)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/docker_sample/Cargo.toml b/docker_sample/Cargo.toml index ba94f64..75606fb 100644 --- a/docker_sample/Cargo.toml +++ b/docker_sample/Cargo.toml @@ -4,8 +4,5 @@ version = "0.1.0" authors = ["docker_sample "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" \ No newline at end of file +actix-web = "3" diff --git a/docker_sample/src/main.rs b/docker_sample/src/main.rs index 29de04d..1dae3e6 100644 --- a/docker_sample/src/main.rs +++ b/docker_sample/src/main.rs @@ -15,7 +15,7 @@ async fn again() -> impl Responder { HttpResponse::Ok().body("Hello world again!") } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { println!("Starting actix-web server"); diff --git a/error_handling/.gitignore b/error_handling/.gitignore deleted file mode 100644 index 53eaa21..0000000 --- a/error_handling/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -**/*.rs.bk diff --git a/error_handling/Cargo.toml b/error_handling/Cargo.toml index 98380fb..ea9de39 100644 --- a/error_handling/Cargo.toml +++ b/error_handling/Cargo.toml @@ -3,12 +3,9 @@ name = "error_handling" version = "1.0.0" authors = ["dowwie "] edition = "2018" -workspace = ".." [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" derive_more = "0.99.2" -futures = "0.3.1" rand = "0.7" env_logger = "0.7" diff --git a/error_handling/src/main.rs b/error_handling/src/main.rs index dce9bb3..da6ad5c 100644 --- a/error_handling/src/main.rs +++ b/error_handling/src/main.rs @@ -87,7 +87,7 @@ async fn do_something() -> Result { Ok(HttpResponse::Ok().body("Nothing interesting happened. Try again.")) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/form/Cargo.toml b/form/Cargo.toml index d3aa62c..d33ffe1 100644 --- a/form/Cargo.toml +++ b/form/Cargo.toml @@ -3,9 +3,10 @@ name = "form-example" version = "1.0.0" authors = ["Gorm Casper "] edition = "2018" -workspace = ".." [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" -serde = { version = "1.0", features = ["derive"] } +actix-web = "3" +serde = { version = "1", features = ["derive"] } + +[dev-dependencies] +actix-rt = "1" diff --git a/form/src/main.rs b/form/src/main.rs index 27635ed..0e0a76c 100644 --- a/form/src/main.rs +++ b/form/src/main.rs @@ -8,7 +8,7 @@ struct AppState { foo: String, } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() diff --git a/hello-world/Cargo.toml b/hello-world/Cargo.toml index bdb31ba..575d8eb 100644 --- a/hello-world/Cargo.toml +++ b/hello-world/Cargo.toml @@ -5,6 +5,8 @@ authors = ["Nikolay Kim "] edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" env_logger = "0.7" + +[dev-dependencies] +actix-rt = "1" diff --git a/hello-world/src/main.rs b/hello-world/src/main.rs index 313cc23..ab04c90 100644 --- a/hello-world/src/main.rs +++ b/hello-world/src/main.rs @@ -5,7 +5,7 @@ async fn index(req: HttpRequest) -> &'static str { "Hello world!" } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/http-proxy/Cargo.toml b/http-proxy/Cargo.toml index f2e8cdc..28cf61f 100644 --- a/http-proxy/Cargo.toml +++ b/http-proxy/Cargo.toml @@ -5,9 +5,6 @@ authors = ["Nikolay Kim ", "Rotem Yaari " edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = { version = "2.0.0", features=["openssl"] } +actix-web = { version = "3", features = ["openssl"] } clap = "2.32.0" -futures = "0.3.1" -failure = "0.1.3" url = "2.0" diff --git a/http-proxy/src/main.rs b/http-proxy/src/main.rs index 4f26193..611f585 100644 --- a/http-proxy/src/main.rs +++ b/http-proxy/src/main.rs @@ -40,7 +40,7 @@ async fn forward( Ok(client_resp.body(res.body().await?)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { let matches = clap::App::new("HTTP Proxy") .arg( diff --git a/json/Cargo.toml b/json/Cargo.toml index 4028ec9..778bfc1 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -2,18 +2,16 @@ name = "json-example" version = "0.1.0" authors = ["Nikolay Kim "] -workspace = ".." edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" actix-service = "1.0.0" - -bytes = "0.5.2" futures = "0.3.1" env_logger = "0.7" - serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" json = "0.12" + +[dev-dependencies] +actix-rt = "1" diff --git a/json/src/main.rs b/json/src/main.rs index 8537b07..df98832 100644 --- a/json/src/main.rs +++ b/json/src/main.rs @@ -1,7 +1,6 @@ use actix_web::{ error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer, }; -use bytes::{Bytes, BytesMut}; use futures::StreamExt; use json::JsonValue; use serde::{Deserialize, Serialize}; @@ -31,7 +30,7 @@ const MAX_SIZE: usize = 262_144; // max payload size is 256k /// This handler manually load request payload and parse json object async fn index_manual(mut payload: web::Payload) -> Result { // payload is a stream of Bytes objects - let mut body = BytesMut::new(); + let mut body = web::BytesMut::new(); while let Some(chunk) = payload.next().await { let chunk = chunk?; // limit max size of in-memory payload @@ -47,7 +46,7 @@ async fn index_manual(mut payload: web::Payload) -> Result } /// This handler manually load request payload and parse json-rust -async fn index_mjsonrust(body: Bytes) -> Result { +async fn index_mjsonrust(body: web::Bytes) -> Result { // body is loaded, now we can deserialize json-rust let result = json::parse(std::str::from_utf8(&body).unwrap()); // return Result let injson: JsonValue = match result { @@ -59,7 +58,7 @@ async fn index_mjsonrust(body: Bytes) -> Result { .body(injson.dump())) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/json_decode_error/Cargo.toml b/json_decode_error/Cargo.toml index 8643844..c80a36a 100644 --- a/json_decode_error/Cargo.toml +++ b/json_decode_error/Cargo.toml @@ -4,9 +4,6 @@ version = "0.1.0" authors = ["Stig Johan Berggren "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" -serde = "1.0.104" +actix-web = "3" +serde = "1" diff --git a/json_decode_error/src/main.rs b/json_decode_error/src/main.rs index 7b1a2ed..c9e1145 100644 --- a/json_decode_error/src/main.rs +++ b/json_decode_error/src/main.rs @@ -29,7 +29,7 @@ fn json_error_handler(err: error::JsonPayloadError, _req: &HttpRequest) -> error error::InternalError::from_response(err, resp).into() } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() diff --git a/json_error/Cargo.toml b/json_error/Cargo.toml index c46a5d7..1404699 100644 --- a/json_error/Cargo.toml +++ b/json_error/Cargo.toml @@ -5,9 +5,7 @@ authors = ["Kai Yao "] edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" failure = "0.1" -futures = "0.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/json_error/src/main.rs b/json_error/src/main.rs index fcf0a01..0bf3975 100644 --- a/json_error/src/main.rs +++ b/json_error/src/main.rs @@ -35,7 +35,7 @@ async fn index() -> Result { }) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { let ip_address = "127.0.0.1:8000"; println!("Running server on {}", ip_address); diff --git a/jsonrpc/Cargo.toml b/jsonrpc/Cargo.toml index e95b7d9..964fdb7 100644 --- a/jsonrpc/Cargo.toml +++ b/jsonrpc/Cargo.toml @@ -3,11 +3,9 @@ name = "jsonrpc-example" version = "2.0.0" authors = ["mohanson "] edition = "2018" -workspace = ".." [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" bytes = "0.5" env_logger = "0.7" futures = "0.3.1" diff --git a/jsonrpc/src/main.rs b/jsonrpc/src/main.rs index c2c5644..c3c2e3d 100644 --- a/jsonrpc/src/main.rs +++ b/jsonrpc/src/main.rs @@ -6,7 +6,6 @@ use std::pin::Pin; use std::sync::{Arc, RwLock}; use std::time::Duration; -use actix_rt::time::delay_for; use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; use bytes::Bytes; use futures::{Future, FutureExt}; @@ -115,7 +114,7 @@ impl ImplNetwork for ObjNetwork { d: u64, ) -> Pin>>>> { async move { - delay_for(Duration::from_secs(d)).await; + actix_web::rt::time::delay_for(Duration::from_secs(d)).await; Ok(String::from("pong")) } .boxed_local() @@ -141,7 +140,7 @@ impl AppState { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "info"); env_logger::init(); diff --git a/juniper-advanced/Cargo.toml b/juniper-advanced/Cargo.toml index bc39e62..3156ca0 100644 --- a/juniper-advanced/Cargo.toml +++ b/juniper-advanced/Cargo.toml @@ -7,9 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" -futures = "0.3.1" +actix-web = "3" juniper = "0.14" diff --git a/juniper-advanced/src/main.rs b/juniper-advanced/src/main.rs index 7a3ab46..c7e6958 100644 --- a/juniper-advanced/src/main.rs +++ b/juniper-advanced/src/main.rs @@ -13,7 +13,7 @@ mod db; mod handlers; mod schemas; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { dotenv::dotenv().ok(); std::env::set_var("RUST_LOG", "actix_web=info,info"); diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 5cddd3a..9f0691a 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -5,8 +5,7 @@ authors = ["pyros2097 "] edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" env_logger = "0.7.1" serde = "1.0.103" serde_json = "1.0.44" diff --git a/juniper/src/main.rs b/juniper/src/main.rs index fd29faa..8d03934 100644 --- a/juniper/src/main.rs +++ b/juniper/src/main.rs @@ -33,7 +33,7 @@ async fn graphql( .body(user)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/middleware/Cargo.toml b/middleware/Cargo.toml index 34bc2c4..e29a10e 100644 --- a/middleware/Cargo.toml +++ b/middleware/Cargo.toml @@ -5,10 +5,9 @@ authors = ["Gorm Casper ", "Sven-Hendrik Haase std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=debug"); env_logger::init(); diff --git a/middleware/src/read_request_body.rs b/middleware/src/read_request_body.rs index c18a7a4..6a34b8a 100644 --- a/middleware/src/read_request_body.rs +++ b/middleware/src/read_request_body.rs @@ -4,8 +4,8 @@ use std::rc::Rc; use std::task::{Context, Poll}; use actix_service::{Service, Transform}; +use actix_web::web::BytesMut; use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error, HttpMessage}; -use bytes::BytesMut; use futures::future::{ok, Future, Ready}; use futures::stream::StreamExt; diff --git a/middleware/src/read_response_body.rs b/middleware/src/read_response_body.rs index 54834dc..b310341 100644 --- a/middleware/src/read_response_body.rs +++ b/middleware/src/read_response_body.rs @@ -5,8 +5,8 @@ use std::task::{Context, Poll}; use actix_service::{Service, Transform}; use actix_web::body::{BodySize, MessageBody, ResponseBody}; +use actix_web::web::{Bytes, BytesMut}; use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error}; -use bytes::{Bytes, BytesMut}; use futures::future::{ok, Ready}; pub struct Logging; @@ -86,13 +86,16 @@ where } } +#[pin_project::pin_project(PinnedDrop)] pub struct BodyLogger { + #[pin] body: ResponseBody, body_accum: BytesMut, } -impl Drop for BodyLogger { - fn drop(&mut self) { +#[pin_project::pinned_drop] +impl PinnedDrop for BodyLogger { + fn drop(self: Pin<&mut Self>) { println!("response body: {:?}", self.body_accum); } } @@ -102,10 +105,15 @@ impl MessageBody for BodyLogger { self.body.size() } - fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll>> { - match self.body.poll_next(cx) { + fn poll_next( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>> { + let this = self.project(); + + match this.body.poll_next(cx) { Poll::Ready(Some(Ok(chunk))) => { - self.body_accum.extend_from_slice(&chunk); + this.body_accum.extend_from_slice(&chunk); Poll::Ready(Some(Ok(chunk))) } Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))), diff --git a/multipart-async-std/Cargo.toml b/multipart-async-std/Cargo.toml index 7f8aa5b..d7c21ec 100644 --- a/multipart-async-std/Cargo.toml +++ b/multipart-async-std/Cargo.toml @@ -10,9 +10,8 @@ repository = "https://github.com/actix/examples" readme = "README.md" [dependencies] +actix-web = "3" +actix-multipart = "0.3" futures = "0.3.1" -actix-multipart = "0.2.0" -actix-web = "2.0.0" -actix-rt = "1.0.0" async-std = "1.4.0" sanitize-filename = "0.2" diff --git a/multipart-async-std/src/main.rs b/multipart-async-std/src/main.rs index 49dbf37..c1ab988 100644 --- a/multipart-async-std/src/main.rs +++ b/multipart-async-std/src/main.rs @@ -38,7 +38,7 @@ fn index() -> HttpResponse { HttpResponse::Ok().body(html) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); async_std::fs::create_dir_all("./tmp").await?; diff --git a/multipart-s3/Cargo.toml b/multipart-s3/Cargo.toml index b2d76f5..e38d05d 100644 --- a/multipart-s3/Cargo.toml +++ b/multipart-s3/Cargo.toml @@ -7,10 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "3" +actix-multipart = "0.3" futures = "0.3.1" -actix-multipart = "0.2.0" -actix-web = "2.0.0" -actix-rt = "1.0.0" rusoto_s3 = "0.43.0" rusoto_core = "0.43.0" bytes = { version = "0.5", features = ["serde"] } diff --git a/multipart-s3/src/main.rs b/multipart-s3/src/main.rs index 7f08f07..2a483ed 100644 --- a/multipart-s3/src/main.rs +++ b/multipart-s3/src/main.rs @@ -72,7 +72,7 @@ fn index() -> HttpResponse { HttpResponse::Ok().body(html) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { dotenv().ok(); let aws_access_key_id = diff --git a/multipart/Cargo.toml b/multipart/Cargo.toml index feaf3d0..440aa21 100644 --- a/multipart/Cargo.toml +++ b/multipart/Cargo.toml @@ -10,8 +10,7 @@ repository = "https://github.com/actix/examples" readme = "README.md" [dependencies] -actix-multipart = "0.2.0" -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-multipart = "0.3" +actix-web = "3" futures = "0.3.1" sanitize-filename = "0.2" diff --git a/multipart/src/main.rs b/multipart/src/main.rs index a8b6327..f0d75c3 100644 --- a/multipart/src/main.rs +++ b/multipart/src/main.rs @@ -10,10 +10,12 @@ async fn save_file(mut payload: Multipart) -> Result { let content_type = field.content_disposition().unwrap(); let filename = content_type.get_filename().unwrap(); let filepath = format!("./tmp/{}", sanitize_filename::sanitize(&filename)); + // File::create is blocking operation, use threadpool let mut f = web::block(|| std::fs::File::create(filepath)) .await .unwrap(); + // Field in turn is stream of *Bytes* object while let Some(chunk) = field.next().await { let data = chunk.unwrap(); @@ -38,7 +40,7 @@ fn index() -> HttpResponse { HttpResponse::Ok().body(html) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); std::fs::create_dir_all("./tmp").unwrap(); diff --git a/openssl/Cargo.toml b/openssl/Cargo.toml index 72ed37a..51ffe1b 100644 --- a/openssl/Cargo.toml +++ b/openssl/Cargo.toml @@ -3,10 +3,8 @@ name = "openssl-example" version = "0.2.0" authors = ["Nikolay Kim "] edition = "2018" -workspace = ".." [dependencies] -actix-rt = "1.0.0" -actix-web = { version = "2.0.0", features = ["openssl"] } +actix-web = { version = "3", features = ["openssl"] } env_logger = "0.7" openssl = "0.10" diff --git a/openssl/src/main.rs b/openssl/src/main.rs index ce050de..d2c679b 100644 --- a/openssl/src/main.rs +++ b/openssl/src/main.rs @@ -11,7 +11,7 @@ async fn index(req: HttpRequest) -> Result { .body("Welcome!")) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=debug"); env_logger::init(); diff --git a/protobuf/Cargo.toml b/protobuf/Cargo.toml index 00a080b..4550a36 100644 --- a/protobuf/Cargo.toml +++ b/protobuf/Cargo.toml @@ -2,7 +2,6 @@ name = "protobuf-example" version = "0.2.0" authors = ["kingxsp , Yuki Okushi "] -workspace = ".." edition = "2018" [dependencies] @@ -11,7 +10,6 @@ env_logger = "0.7.1" prost = "0.6.1" prost-derive = "0.6.1" -actix = "0.9.0" -actix-protobuf = "0.5.0" -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix = "0.10" +actix-protobuf = "0.6" +actix-web = "3" diff --git a/protobuf/src/main.rs b/protobuf/src/main.rs index 61dd729..fdd7c8a 100644 --- a/protobuf/src/main.rs +++ b/protobuf/src/main.rs @@ -8,6 +8,7 @@ use actix_web::*; pub struct MyObj { #[prost(int32, tag = "1")] pub number: i32, + #[prost(string, tag = "2")] pub name: String, } @@ -17,7 +18,7 @@ async fn index(msg: ProtoBuf) -> Result { HttpResponse::Ok().protobuf(msg.0) // <- send response } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info"); env_logger::init(); diff --git a/r2d2/Cargo.toml b/r2d2/Cargo.toml index e924fe4..2a2db6b 100644 --- a/r2d2/Cargo.toml +++ b/r2d2/Cargo.toml @@ -5,10 +5,8 @@ authors = ["Nikolay Kim "] edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-web = "3" -futures = "0.3.1" env_logger = "0.7" uuid = { version = "0.8", features = ["v4"] } diff --git a/r2d2/src/main.rs b/r2d2/src/main.rs index 4cbbb24..4d34355 100644 --- a/r2d2/src/main.rs +++ b/r2d2/src/main.rs @@ -31,7 +31,7 @@ async fn index( Ok(res) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=debug"); env_logger::init(); diff --git a/redis-session/Cargo.toml b/redis-session/Cargo.toml index 9d3934a..5cbddc3 100644 --- a/redis-session/Cargo.toml +++ b/redis-session/Cargo.toml @@ -5,14 +5,16 @@ authors = ["Nikolay Kim ", "dowwie "] edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" -actix-session = "0.3.0" -actix-redis = { version = "0.8.0", features = ["web"] } +actix-web = "3" +actix-session = "0.4" +actix-redis = "0.9" env_logger = "0.7" -serde = { version = "^1.0", features = ["derive"] } -actix-service = "1.0.0" -actix-http = "1.0.0" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +actix-service = "1" +actix-http = "2" rand = "0.7.3" -serde_json = "1.0.40" -time = "0.1.42" +time = "0.2" + +[dev-dependencies] +actix-rt = "1" diff --git a/redis-session/src/main.rs b/redis-session/src/main.rs index 8cd2aed..8008743 100644 --- a/redis-session/src/main.rs +++ b/redis-session/src/main.rs @@ -72,7 +72,7 @@ async fn logout(session: Session) -> Result { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info,actix_redis=info"); env_logger::init(); @@ -308,7 +308,9 @@ mod test { .into_iter() .find(|c| c.name() == "test-session") .unwrap(); - assert!(&time::now().tm_year != &cookie_4.expires().map(|t| t.tm_year).unwrap()); + + let now = time::OffsetDateTime::now_utc(); + assert!(now.year() != cookie_4.expires().map(|t| t.year()).unwrap()); // Step 10: GET index, including session cookie #2 in request // - set-cookie actix-session will be in response (session cookie #3) diff --git a/redis/Cargo.toml b/redis/Cargo.toml index db64a47..8b95b1b 100644 --- a/redis/Cargo.toml +++ b/redis/Cargo.toml @@ -5,11 +5,10 @@ authors = ["dowwie "] edition = "2018" [dependencies] -actix = "0.9.0" -actix-rt = "1.0.0" -actix-web = "2.0.0" -actix-redis = "0.8.0" -futures = "0.3.1" -redis-async = "0.6.1" -serde = { version = "1.0.71", features = ["derive"] } +actix = "0.10" +actix-web = "3" +actix-redis = "0.9" +futures = "0.3" +redis-async = "0.6.3" +serde = { version = "1", features = ["derive"] } env_logger = "0.7" diff --git a/redis/src/main.rs b/redis/src/main.rs index 268face..bedbe18 100644 --- a/redis/src/main.rs +++ b/redis/src/main.rs @@ -1,12 +1,9 @@ -#[macro_use] -extern crate redis_async; -use serde::Deserialize; - use actix::prelude::*; use actix_redis::{Command, RedisActor}; use actix_web::{middleware, web, App, Error as AWError, HttpResponse, HttpServer}; use futures::future::join_all; -use redis_async::resp::RespValue; +use redis_async::{resp::RespValue, resp_array}; +use serde::Deserialize; #[derive(Deserialize)] pub struct CacheInfo { @@ -74,7 +71,7 @@ async fn del_stuff(redis: web::Data>) -> Result std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=trace,actix_redis=trace"); env_logger::init(); diff --git a/run-in-thread/Cargo.toml b/run-in-thread/Cargo.toml index cb00f1d..72482f0 100644 --- a/run-in-thread/Cargo.toml +++ b/run-in-thread/Cargo.toml @@ -6,6 +6,5 @@ edition = "2018" description = "Run actix-web in separate thread" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" env_logger = "0.7" diff --git a/run-in-thread/src/main.rs b/run-in-thread/src/main.rs index bcae81b..3a0c504 100644 --- a/run-in-thread/src/main.rs +++ b/run-in-thread/src/main.rs @@ -1,8 +1,7 @@ use std::sync::mpsc; use std::{thread, time}; -use actix_rt::System; -use actix_web::{dev::Server, middleware, web, App, HttpRequest, HttpServer}; +use actix_web::{dev::Server, middleware, rt, web, App, HttpRequest, HttpServer}; async fn index(req: HttpRequest) -> &'static str { println!("REQ: {:?}", req); @@ -10,7 +9,7 @@ async fn index(req: HttpRequest) -> &'static str { } fn run_app(tx: mpsc::Sender) -> std::io::Result<()> { - let mut sys = System::new("test"); + let mut sys = rt::System::new("test"); // srv is server controller type, `dev::Server` let srv = HttpServer::new(|| { @@ -48,5 +47,5 @@ fn main() { println!("STOPPING SERVER"); // init stop server and wait until server gracefully exit - System::new("").block_on(srv.stop(true)); + rt::System::new("").block_on(srv.stop(true)); } diff --git a/rustls/Cargo.toml b/rustls/Cargo.toml index fc7c1b8..dc97d6d 100644 --- a/rustls/Cargo.toml +++ b/rustls/Cargo.toml @@ -2,7 +2,6 @@ name = "rustls-example" version = "1.0.0" authors = ["Nikolay Kim "] -workspace = ".." edition = "2018" [[bin]] @@ -11,7 +10,6 @@ path = "src/main.rs" [dependencies] env_logger = "0.7" -rustls = "0.16" -actix-web = { version = "2.0.0", features = ["rustls"] } -actix-files = "0.2.1" -actix-rt = "1.0.0" +rustls = "0.18" +actix-web = { version = "3", features = ["rustls"] } +actix-files = "0.3" diff --git a/rustls/src/main.rs b/rustls/src/main.rs index a5be717..b86b4e3 100644 --- a/rustls/src/main.rs +++ b/rustls/src/main.rs @@ -14,7 +14,7 @@ async fn index(req: HttpRequest) -> HttpResponse { .body("Welcome!") } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { if std::env::var("RUST_LOG").is_err() { std::env::set_var("RUST_LOG", "actix_web=info"); diff --git a/server-sent-events/Cargo.toml b/server-sent-events/Cargo.toml index cf4d666..d962926 100644 --- a/server-sent-events/Cargo.toml +++ b/server-sent-events/Cargo.toml @@ -2,12 +2,10 @@ name = "server-sent-events" version = "1.0.0" authors = ["Arve Seljebu"] -workspace = ".." edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-web = "3" env_logger = "0.7" futures = "0.3.1" -tokio = "0.2" +tokio = { version = "0.2", features = ["sync"] } diff --git a/server-sent-events/benchmark.js b/server-sent-events/benchmark.js index 452d75d..68c4ad5 100644 --- a/server-sent-events/benchmark.js +++ b/server-sent-events/benchmark.js @@ -1,6 +1,6 @@ const http = require('http') -const n = 1000; +const n = 100; let connected = 0; let messages = 0; let start = Date.now(); diff --git a/server-sent-events/src/main.rs b/server-sent-events/src/main.rs index 3c3d858..e0ab030 100644 --- a/server-sent-events/src/main.rs +++ b/server-sent-events/src/main.rs @@ -3,13 +3,13 @@ use std::sync::Mutex; use std::task::{Context, Poll}; use std::time::Duration; +use actix_web::rt::time::{interval_at, Instant}; use actix_web::web::{Bytes, Data, Path}; use actix_web::{web, App, Error, HttpResponse, HttpServer, Responder}; use futures::{Stream, StreamExt}; use tokio::sync::mpsc::{channel, Receiver, Sender}; -use tokio::time::{interval_at, Instant}; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init(); let data = Broadcaster::create(); @@ -39,7 +39,6 @@ async fn new_client(broadcaster: Data>) -> impl Responder { HttpResponse::Ok() .header("content-type", "text/event-stream") - .no_chunking() .streaming(rx) } @@ -74,7 +73,7 @@ impl Broadcaster { } fn spawn_ping(me: Data>) { - actix_rt::spawn(async move { + actix_web::rt::spawn(async move { let mut task = interval_at(Instant::now(), Duration::from_secs(10)); while let Some(_) = task.next().await { me.lock().unwrap().remove_stale_clients(); diff --git a/shutdown-server/Cargo.toml b/shutdown-server/Cargo.toml index 4eb2741..d41f056 100644 --- a/shutdown-server/Cargo.toml +++ b/shutdown-server/Cargo.toml @@ -6,8 +6,7 @@ edition = "2018" description = "Send a request to the server to shut it down" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-web = "3" env_logger = "0.7" futures = "0.3" -tokio = { version = "0.2.11", features = ["signal"] } +tokio = { version = "0.2", features = ["signal"] } diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index f16ab51..6ab6bdc 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -15,7 +15,7 @@ async fn stop(stopper: web::Data>) -> HttpResponse { HttpResponse::NoContent().finish() } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=debug,actix_web=debug"); env_logger::init(); diff --git a/simple-auth-server/Cargo.toml b/simple-auth-server/Cargo.toml index 240ae95..15f5694 100644 --- a/simple-auth-server/Cargo.toml +++ b/simple-auth-server/Cargo.toml @@ -6,20 +6,21 @@ edition = "2018" workspace = ".." [dependencies] -actix-identity = "0.2.0" -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" +actix-identity = "0.3" + # FIXME: Specify the commit hash to use bindgen v0.50. argonautica = { git = "https://github.com/bcmyers/argonautica", rev = "67fc8d8d7d67696cd8ca7a59b92531f06b089212" } chrono = { version = "0.4.6", features = ["serde"] } derive_more = "0.99.0" -diesel = { version = "1.4.2", features = ["postgres", "uuidv07", "r2d2", "chrono"] } +diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "r2d2", "chrono"] } dotenv = "0.15" env_logger = "0.7" futures = "0.3.1" r2d2 = "0.8" -lazy_static = "1.3.0" +lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sparkpost = "0.5.2" uuid = { version = "0.8", features = ["serde", "v4"] } +time = "0.2" diff --git a/simple-auth-server/src/main.rs b/simple-auth-server/src/main.rs index 929ee2c..15c131b 100644 --- a/simple-auth-server/src/main.rs +++ b/simple-auth-server/src/main.rs @@ -5,6 +5,7 @@ use actix_identity::{CookieIdentityPolicy, IdentityService}; use actix_web::{middleware, web, App, HttpServer}; use diesel::prelude::*; use diesel::r2d2::{self, ConnectionManager}; +use time::Duration; mod auth_handler; mod email_service; @@ -15,7 +16,7 @@ mod register_handler; mod schema; mod utils; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { dotenv::dotenv().ok(); std::env::set_var( @@ -44,7 +45,7 @@ async fn main() -> std::io::Result<()> { .name("auth") .path("/") .domain(domain.as_str()) - .max_age_time(chrono::Duration::days(1)) + .max_age_time(Duration::days(1)) .secure(false), // this can only be true if you have https )) .data(web::JsonConfig::default().limit(4096)) diff --git a/sqlx_todo/Cargo.toml b/sqlx_todo/Cargo.toml index 954a1e2..b2ddb8f 100644 --- a/sqlx_todo/Cargo.toml +++ b/sqlx_todo/Cargo.toml @@ -7,14 +7,12 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "3" listenfd = "0.3.3" -actix-web = "2.0.0" -actix-rt = "1.1.0" serde = "1.0.106" serde_json = "1.0.51" sqlx = { version = "0.3", features = [ "postgres" ] } -futures = "0.3.4" dotenv = "0.15.0" env_logger = "0.7.1" log = "0.4.8" -anyhow = "1.0.28" \ No newline at end of file +anyhow = "1.0.28" diff --git a/sqlx_todo/src/main.rs b/sqlx_todo/src/main.rs index 1a0f147..4c44d5b 100644 --- a/sqlx_todo/src/main.rs +++ b/sqlx_todo/src/main.rs @@ -25,7 +25,7 @@ async fn index() -> impl Responder { ) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> Result<()> { dotenv().ok(); env_logger::init(); @@ -56,4 +56,4 @@ async fn main() -> Result<()> { server.run().await?; Ok(()) -} \ No newline at end of file +} diff --git a/state/Cargo.toml b/state/Cargo.toml index 6fc7de0..e3f3d12 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -5,7 +5,5 @@ authors = ["Nikolay Kim "] edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" -futures = "0.3.1" +actix-web = "3" env_logger = "0.7" diff --git a/state/src/main.rs b/state/src/main.rs index cad3a57..f984e7a 100644 --- a/state/src/main.rs +++ b/state/src/main.rs @@ -48,7 +48,7 @@ async fn index( HttpResponse::Ok().body(body) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/static_index/Cargo.toml b/static_index/Cargo.toml index af5cc11..616a23e 100644 --- a/static_index/Cargo.toml +++ b/static_index/Cargo.toml @@ -2,13 +2,9 @@ name = "static_index" version = "2.0.0" authors = ["Jose Marinez "] -workspace = ".." edition = "2018" [dependencies] -futures = "0.3.1" +actix-web = "3" +actix-files = "0.3" env_logger = "0.7" - -actix-web = "2.0.0" -actix-files = "0.2.1" -actix-rt = "1.0.0" diff --git a/static_index/src/main.rs b/static_index/src/main.rs index 2879da5..fab6eea 100644 --- a/static_index/src/main.rs +++ b/static_index/src/main.rs @@ -1,7 +1,7 @@ use actix_files::Files; use actix_web::{middleware, App, HttpServer}; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/template_askama/Cargo.toml b/template_askama/Cargo.toml index c8672d1..27b7050 100644 --- a/template_askama/Cargo.toml +++ b/template_askama/Cargo.toml @@ -5,8 +5,7 @@ authors = ["Nikolay Kim "] edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" askama = "0.9" [build-dependencies] diff --git a/template_askama/src/main.rs b/template_askama/src/main.rs index d78d050..5b0e6fa 100644 --- a/template_askama/src/main.rs +++ b/template_askama/src/main.rs @@ -28,7 +28,7 @@ async fn index(query: web::Query>) -> Result std::io::Result<()> { // start http server HttpServer::new(move || { diff --git a/template_handlebars/Cargo.toml b/template_handlebars/Cargo.toml index ddb8297..df5ad1b 100644 --- a/template_handlebars/Cargo.toml +++ b/template_handlebars/Cargo.toml @@ -5,8 +5,7 @@ authors = ["Alexandru Tiniuc "] edition = "2018" [dependencies] -actix-http = "1.0.1" -actix-rt = "1.0.0" -actix-web = "2.0.0" +actix-http = "2" +actix-web = "3" handlebars = { version = "3.0.0", features = ["dir_source"] } serde_json = "1.0" diff --git a/template_handlebars/src/main.rs b/template_handlebars/src/main.rs index 60f1524..3fddb49 100644 --- a/template_handlebars/src/main.rs +++ b/template_handlebars/src/main.rs @@ -39,7 +39,7 @@ async fn user( HttpResponse::Ok().body(body) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { // Handlebars uses a repository for the compiled templates. This object must be // shared between the application threads, and is therefore passed to the diff --git a/template_tera/Cargo.toml b/template_tera/Cargo.toml index 591a577..96f6d41 100644 --- a/template_tera/Cargo.toml +++ b/template_tera/Cargo.toml @@ -2,12 +2,10 @@ name = "template-tera" version = "2.0.0" authors = ["Nikolay Kim "] -workspace = ".." edition = "2018" [dependencies] env_logger = "0.7" tera = "1.0" -actix-http = "1.0.1" -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-http = "2" +actix-web = "3" diff --git a/template_tera/src/main.rs b/template_tera/src/main.rs index 85fdd13..7507837 100644 --- a/template_tera/src/main.rs +++ b/template_tera/src/main.rs @@ -26,7 +26,7 @@ async fn index( Ok(HttpResponse::Ok().content_type("text/html").body(s)) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/template_yarte/Cargo.toml b/template_yarte/Cargo.toml index 379dd6c..27aa949 100644 --- a/template_yarte/Cargo.toml +++ b/template_yarte/Cargo.toml @@ -5,17 +5,15 @@ authors = ["Juan Aguilar Santillana "] publish = false edition = "2018" -workspace = ".." - [dependencies] +actix-web = "3" env_logger = "0.7" - yarte = { version = "0.8", features = ["html-min"] } -actix-rt = "1.0" -actix-web = "2.0.0" - [build-dependencies.yarte_helpers] version = "0.8" default-features = false features = ["config"] + +[dev-dependencies] +actix-rt = "1" diff --git a/template_yarte/src/main.rs b/template_yarte/src/main.rs index 1a9ffba..a4368f1 100644 --- a/template_yarte/src/main.rs +++ b/template_yarte/src/main.rs @@ -26,7 +26,7 @@ async fn index( .map_err(|_| ErrorInternalServerError("Some error message")) } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/todo/Cargo.toml b/todo/Cargo.toml index 3022972..1b9db82 100644 --- a/todo/Cargo.toml +++ b/todo/Cargo.toml @@ -5,10 +5,10 @@ version = "2.0.0" edition = "2018" [dependencies] -actix-web = "2.0.0" -actix-files = "0.2.1" -actix-session = "0.3.0" -actix-rt = "1.0.0" +actix-web = "3" +actix-files = "0.3" +actix-session = "0.4" + dotenv = "0.15" env_logger = "0.7" futures = "0.3.1" diff --git a/todo/src/main.rs b/todo/src/main.rs index 9b610b0..26d9484 100644 --- a/todo/src/main.rs +++ b/todo/src/main.rs @@ -20,7 +20,7 @@ mod session; static SESSION_SIGNING_KEY: &[u8] = &[0; 32]; -#[actix_rt::main] +#[actix_web::main] async fn main() -> io::Result<()> { dotenv().ok(); diff --git a/udp-echo/Cargo.toml b/udp-echo/Cargo.toml index 380ec0e..f06102f 100644 --- a/udp-echo/Cargo.toml +++ b/udp-echo/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Anton Patrushev "] edition = "2018" [dependencies] -actix = "0.9" +actix = "0.10" actix-rt = "1.1" tokio = "0.2" tokio-util = { version = "0.3", features = [ "codec", "udp" ] } diff --git a/unix-socket/Cargo.toml b/unix-socket/Cargo.toml index 0d924f6..376ef48 100644 --- a/unix-socket/Cargo.toml +++ b/unix-socket/Cargo.toml @@ -2,10 +2,8 @@ name = "unix-socket" version = "1.0.0" authors = ["Messense Lv "] -workspace = ".." edition = "2018" [dependencies] env_logger = "0.7" -actix-web = "2.0.0" -actix-rt = "1.0.0" +actix-web = "3" diff --git a/unix-socket/src/main.rs b/unix-socket/src/main.rs index 6178b7a..e715f5e 100644 --- a/unix-socket/src/main.rs +++ b/unix-socket/src/main.rs @@ -4,7 +4,7 @@ async fn index(_req: HttpRequest) -> &'static str { "Hello world!" } -#[actix_rt::main] +#[actix_web::main] #[cfg(unix)] async fn main() -> std::io::Result<()> { ::std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); diff --git a/web-cors/backend/.gitignore b/web-cors/backend/.gitignore deleted file mode 100644 index 250b626..0000000 --- a/web-cors/backend/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ - -/target/ -**/*.rs.bk -Cargo.lock \ No newline at end of file diff --git a/web-cors/backend/Cargo.toml b/web-cors/backend/Cargo.toml index fd9f217..9a26563 100644 --- a/web-cors/backend/Cargo.toml +++ b/web-cors/backend/Cargo.toml @@ -5,9 +5,9 @@ authors = ["krircc "] edition = "2018" [dependencies] -actix-rt = "1.0.0" -actix-web = "2.0.0" -actix-cors = "0.2.0" +actix-web = "3" +actix-cors = "0.3" + serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" env_logger = "0.7" diff --git a/web-cors/backend/src/main.rs b/web-cors/backend/src/main.rs index 23fb8d8..b88f239 100644 --- a/web-cors/backend/src/main.rs +++ b/web-cors/backend/src/main.rs @@ -3,7 +3,7 @@ use actix_web::{http::header, middleware::Logger, web, App, HttpServer}; mod user; -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); diff --git a/websocket-autobahn/Cargo.toml b/websocket-autobahn/Cargo.toml index 04111d7..1d27d46 100644 --- a/websocket-autobahn/Cargo.toml +++ b/websocket-autobahn/Cargo.toml @@ -9,8 +9,7 @@ name = "websocket-autobahn-server" path = "src/main.rs" [dependencies] -actix = "0.9.0" -actix-web = "2.0.0" -actix-web-actors = "2.0.0" -actix-rt = "1.0.0" +actix = "0.10" +actix-web = "3" +actix-web-actors = "3" env_logger = "0.7" diff --git a/websocket-autobahn/src/main.rs b/websocket-autobahn/src/main.rs index d42dc24..5ae97b8 100644 --- a/websocket-autobahn/src/main.rs +++ b/websocket-autobahn/src/main.rs @@ -43,7 +43,7 @@ impl WebSocket { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); env_logger::init(); diff --git a/websocket-chat-broker/Cargo.toml b/websocket-chat-broker/Cargo.toml index cf7fcbd..137db28 100644 --- a/websocket-chat-broker/Cargo.toml +++ b/websocket-chat-broker/Cargo.toml @@ -13,11 +13,11 @@ path = "src/main.rs" [dependencies] actix = "0.9" -actix-broker = "0.3.0" +actix-broker = "0.3" actix-files = "0.2" -actix-rt = "1.1" -actix-web = "2.0" -actix-web-actors = "2.0" +actix-rt = "1" +actix-web = "2" +actix-web-actors = "2" env_logger = "0.7" futures = "0.3" log = "0.4" diff --git a/websocket-chat/Cargo.toml b/websocket-chat/Cargo.toml index c11360c..339169a 100644 --- a/websocket-chat/Cargo.toml +++ b/websocket-chat/Cargo.toml @@ -9,16 +9,15 @@ name = "websocket-chat-server" path = "src/main.rs" [dependencies] -actix-rt = "1.0.0" -actix = "0.9.0" -actix-web = "2.0.0" -actix-web-actors = "2.0.0" -actix-files = "0.2.1" +actix = "0.10" +actix-web = "3" +actix-web-actors = "3" +actix-files = "0.3" rand = "0.7" -bytes = "0.5.3" -byteorder = "1.1" -futures = "0.3.1" +bytes = "0.5" +byteorder = "1.3" +futures = "0.3" env_logger = "0.7" -serde = "1.0" -serde_json = "1.0" +serde = "1" +serde_json = "1" diff --git a/websocket-chat/src/main.rs b/websocket-chat/src/main.rs index 3b28b7f..ef4aee3 100644 --- a/websocket-chat/src/main.rs +++ b/websocket-chat/src/main.rs @@ -220,7 +220,7 @@ impl WsChatSession { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init(); diff --git a/websocket-tcp-chat/Cargo.toml b/websocket-tcp-chat/Cargo.toml index b62b819..06e7174 100644 --- a/websocket-tcp-chat/Cargo.toml +++ b/websocket-tcp-chat/Cargo.toml @@ -13,12 +13,11 @@ name = "websocket-tcp-client" path = "src/client.rs" [dependencies] -actix = "0.9.0" -actix-web = "2.0.0" -actix-web-actors = "2.0.0" -actix-files = "0.2.1" -actix-rt = "1.0.0" -actix-codec = "0.2.0" +actix = "0.10" +actix-web = "3" +actix-web-actors = "3" +actix-files = "0.3" +actix-codec = "0.3" rand = "0.7" bytes = "0.5.3" @@ -28,4 +27,4 @@ env_logger = "0.7" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = "0.2.4" -tokio-util = "0.2.0" +tokio-util = "0.3" diff --git a/websocket-tcp-chat/src/client.rs b/websocket-tcp-chat/src/client.rs index df26b16..b4d442b 100644 --- a/websocket-tcp-chat/src/client.rs +++ b/websocket-tcp-chat/src/client.rs @@ -8,7 +8,7 @@ use tokio_util::codec::FramedRead; mod codec; -#[actix_rt::main] +#[actix_web::main] async fn main() { // Connect to server let addr = net::SocketAddr::from_str("127.0.0.1:12345").unwrap(); @@ -38,7 +38,11 @@ async fn main() { } struct ChatClient { - framed: actix::io::FramedWrite, codec::ClientChatCodec>, + framed: actix::io::FramedWrite< + codec::ChatRequest, + WriteHalf, + codec::ClientChatCodec, + >, } #[derive(Message)] diff --git a/websocket-tcp-chat/src/codec.rs b/websocket-tcp-chat/src/codec.rs index 56f4717..098e71e 100644 --- a/websocket-tcp-chat/src/codec.rs +++ b/websocket-tcp-chat/src/codec.rs @@ -65,8 +65,7 @@ impl Decoder for ChatCodec { } } -impl Encoder for ChatCodec { - type Item = ChatResponse; +impl Encoder for ChatCodec { type Error = io::Error; fn encode( @@ -110,8 +109,7 @@ impl Decoder for ClientChatCodec { } } -impl Encoder for ClientChatCodec { - type Item = ChatRequest; +impl Encoder for ClientChatCodec { type Error = io::Error; fn encode( diff --git a/websocket-tcp-chat/src/main.rs b/websocket-tcp-chat/src/main.rs index b85e443..542f886 100644 --- a/websocket-tcp-chat/src/main.rs +++ b/websocket-tcp-chat/src/main.rs @@ -219,7 +219,7 @@ impl WsChatSession { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { env_logger::init(); diff --git a/websocket-tcp-chat/src/session.rs b/websocket-tcp-chat/src/session.rs index 1481db9..4ddcf05 100644 --- a/websocket-tcp-chat/src/session.rs +++ b/websocket-tcp-chat/src/session.rs @@ -31,7 +31,7 @@ pub struct ChatSession { /// joined room room: String, /// Framed wrapper - framed: actix::io::FramedWrite, ChatCodec>, + framed: actix::io::FramedWrite, ChatCodec>, } impl Actor for ChatSession { @@ -136,7 +136,7 @@ impl Handler for ChatSession { impl ChatSession { pub fn new( addr: Addr, - framed: actix::io::FramedWrite, ChatCodec>, + framed: actix::io::FramedWrite, ChatCodec>, ) -> ChatSession { ChatSession { id: 0, @@ -176,7 +176,7 @@ pub fn tcp_server(_s: &str, server: Addr) { // Create server listener let addr = net::SocketAddr::from_str("127.0.0.1:12345").unwrap(); - actix_rt::spawn(async move { + actix_web::rt::spawn(async move { let server = server.clone(); let mut listener = TcpListener::bind(&addr).await.unwrap(); let mut incoming = listener.incoming(); diff --git a/websocket/Cargo.toml b/websocket/Cargo.toml index 7a25687..40d5c41 100644 --- a/websocket/Cargo.toml +++ b/websocket/Cargo.toml @@ -13,13 +13,12 @@ name = "websocket-client" path = "src/client.rs" [dependencies] -actix = "0.9.0" -actix-codec = "0.2.0" -actix-web = "2.0.0" -actix-web-actors = "2.0.0" -actix-files = "0.2.1" -actix-rt = "1.0.0" -awc = "1.0.1" +actix = "0.10" +actix-codec = "0.3" +actix-web = "3" +actix-web-actors = "3" +actix-files = "0.3" +awc = "2" env_logger = "0.7" futures = "0.3.1" bytes = "0.5.3" diff --git a/websocket/src/main.rs b/websocket/src/main.rs index efa05fa..0476347 100644 --- a/websocket/src/main.rs +++ b/websocket/src/main.rs @@ -95,7 +95,7 @@ impl MyWebSocket { } } -#[actix_rt::main] +#[actix_web::main] async fn main() -> std::io::Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); env_logger::init();