diff --git a/async_pg/src/main.rs b/async_pg/src/main.rs index c830b200..80d154aa 100644 --- a/async_pg/src/main.rs +++ b/async_pg/src/main.rs @@ -1,6 +1,6 @@ mod config { - use serde::Deserialize; pub use ::config::ConfigError; + use serde::Deserialize; #[derive(Deserialize)] pub struct Config { pub server_addr: String, @@ -49,7 +49,9 @@ mod errors { fn error_response(&self) -> HttpResponse { match *self { MyError::NotFound => HttpResponse::NotFound().finish(), - MyError::PoolError(ref err) => HttpResponse::InternalServerError().body(err.to_string()), + MyError::PoolError(ref err) => { + HttpResponse::InternalServerError().body(err.to_string()) + } _ => HttpResponse::InternalServerError().finish(), } } @@ -98,7 +100,7 @@ mod handlers { let client: Client = db_pool.get().await.map_err(|err| MyError::PoolError(err))?; - + let new_user = db::add_user(&client, user_info).await?; Ok(HttpResponse::Ok().json(new_user)) @@ -108,9 +110,8 @@ mod handlers { use actix_web::{web, App, HttpServer}; use dotenv::dotenv; use handlers::add_user; -use tokio_postgres::NoTls; use tokio::signal::unix::{signal, SignalKind}; - +use tokio_postgres::NoTls; #[actix_rt::main] async fn main() -> std::io::Result<()> { @@ -129,14 +130,14 @@ async fn main() -> std::io::Result<()> { println!("Server running at http://{}/", config.server_addr); let srv = server.clone(); - let mut stream = signal(SignalKind::interrupt())?; + let mut stream = signal(SignalKind::interrupt())?; actix_rt::spawn(async move { loop { stream.recv().await; println!("\nSIGINT Received. Stopping server.\n"); srv.stop(true).await; } - }); + }); server.await } diff --git a/basics/src/main.rs b/basics/src/main.rs index efd57f24..2fee54f5 100644 --- a/basics/src/main.rs +++ b/basics/src/main.rs @@ -92,13 +92,11 @@ async fn main() -> io::Result<()> { _ => HttpResponse::NotFound(), }), ) - .service(web::resource("/error").to(|| { - async { - error::InternalError::new( - io::Error::new(io::ErrorKind::Other, "test"), - StatusCode::INTERNAL_SERVER_ERROR, - ) - } + .service(web::resource("/error").to(|| async { + error::InternalError::new( + io::Error::new(io::ErrorKind::Other, "test"), + StatusCode::INTERNAL_SERVER_ERROR, + ) })) // static files .service(fs::Files::new("/static", "static").show_files_listing()) diff --git a/middleware/src/main.rs b/middleware/src/main.rs index 1598a2a0..c2237beb 100644 --- a/middleware/src/main.rs +++ b/middleware/src/main.rs @@ -30,13 +30,11 @@ async fn main() -> std::io::Result<()> { res }) }) - .service(web::resource("/login").to(|| { - async { - "You are on /login. Go to src/redirect.rs to change this behavior." - } + .service(web::resource("/login").to(|| async { + "You are on /login. Go to src/redirect.rs to change this behavior." })) - .service(web::resource("/").to(|| { - async { "Hello, middleware! Check the console where the server is run." } + .service(web::resource("/").to(|| async { + "Hello, middleware! Check the console where the server is run." })) }) .bind("127.0.0.1:8080")? diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index 962b5c20..72cb0f7e 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -1,9 +1,8 @@ -use std::{sync::mpsc, thread}; use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; use futures::executor; +use std::{sync::mpsc, thread}; use tokio::signal::unix::{signal, SignalKind}; - #[get("/hello")] async fn hello() -> &'static str { "Hello world!" @@ -59,7 +58,7 @@ async fn main() -> std::io::Result<()> { println!("\n*** SIGINT received. Stopping server, gracefully. ***\n"); stopper.send(()).unwrap(); } - }); + }); // run server server.await