diff --git a/async_pg/src/main.rs b/async_pg/src/main.rs index ad3dc98..19f4f21 100644 --- a/async_pg/src/main.rs +++ b/async_pg/src/main.rs @@ -98,8 +98,7 @@ mod handlers { ) -> Result { let user_info: User = user.into_inner(); - let client: Client = - db_pool.get().await.map_err(MyError::PoolError)?; + let client: Client = db_pool.get().await.map_err(MyError::PoolError)?; let new_user = db::add_user(&client, user_info).await?; diff --git a/awc_https/src/main.rs b/awc_https/src/main.rs index 2958ea9..5b3d183 100644 --- a/awc_https/src/main.rs +++ b/awc_https/src/main.rs @@ -1,15 +1,17 @@ -use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, client::{Client, Connector}}; +use actix_web::{ + client::{Client, Connector}, + web, App, HttpRequest, HttpResponse, HttpServer, +}; use openssl::ssl::{SslConnector, SslMethod}; - async fn index(_req: HttpRequest) -> HttpResponse { - let builder = SslConnector::builder(SslMethod::tls()).unwrap(); + let builder = SslConnector::builder(SslMethod::tls()).unwrap(); let client = Client::build() .connector(Connector::new().ssl(builder.build()).finish()) .finish(); - let now = std::time::Instant::now(); + let now = std::time::Instant::now(); let payload = client .get("https://upload.wikimedia.org/wikipedia/commons/f/ff/Pizigani_1367_Chart_10MB.jpg") @@ -21,22 +23,20 @@ async fn index(_req: HttpRequest) -> HttpResponse { .await .unwrap(); - println!("awc time elapsed while reading bytes into memory: {} ms", now.elapsed().as_millis()); + println!( + "awc time elapsed while reading bytes into memory: {} ms", + now.elapsed().as_millis() + ); - HttpResponse::Ok() - .content_type("image/jpeg") - .body(payload) + HttpResponse::Ok().content_type("image/jpeg").body(payload) } #[actix_rt::main] async fn main() -> std::io::Result<()> { let port = 3000; - HttpServer::new(|| { - App::new() - .service(web::resource("/").to(index)) - }) - .bind(("0.0.0.0", port))? - .run() - .await + HttpServer::new(|| App::new().service(web::resource("/").to(index))) + .bind(("0.0.0.0", port))? + .run() + .await } diff --git a/docker_sample/src/main.rs b/docker_sample/src/main.rs index af38893..22b0371 100644 --- a/docker_sample/src/main.rs +++ b/docker_sample/src/main.rs @@ -19,12 +19,8 @@ async fn again() -> impl Responder { async fn main() -> std::io::Result<()> { println!("Starting actix-web server"); - HttpServer::new(|| { - App::new() - .service(index) - .service(again) - }) - .bind("0.0.0.0:5000")? - .run() - .await -} \ No newline at end of file + HttpServer::new(|| App::new().service(index).service(again)) + .bind("0.0.0.0:5000")? + .run() + .await +} diff --git a/graphql-demo/src/schemas/user.rs b/graphql-demo/src/schemas/user.rs index 69ed3dc..d17e293 100644 --- a/graphql-demo/src/schemas/user.rs +++ b/graphql-demo/src/schemas/user.rs @@ -33,27 +33,26 @@ impl User { fn products(&self, context: &Context) -> Vec { let mut conn = context.dbpool.get().unwrap(); - conn - .prep_exec( - "select * from product where user_id=:user_id", - params! { - "user_id" => &self.id - }, - ) - .map(|result| { - result - .map(|x| x.unwrap()) - .map(|mut row| { - let (id, user_id, name, price) = from_row(row); - Product { - id, - user_id, - name, - price, - } - }) - .collect() - }) - .unwrap() + conn.prep_exec( + "select * from product where user_id=:user_id", + params! { + "user_id" => &self.id + }, + ) + .map(|result| { + result + .map(|x| x.unwrap()) + .map(|mut row| { + let (id, user_id, name, price) = from_row(row); + Product { + id, + user_id, + name, + price, + } + }) + .collect() + }) + .unwrap() } } diff --git a/shutdown-server/src/main.rs b/shutdown-server/src/main.rs index 6356c20..8a830ae 100644 --- a/shutdown-server/src/main.rs +++ b/shutdown-server/src/main.rs @@ -2,7 +2,6 @@ use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer}; use futures::executor; use std::{sync::mpsc, thread}; - #[get("/hello")] async fn hello() -> &'static str { "Hello world!"