1
0
mirror of https://github.com/actix/examples synced 2025-03-20 18:45:17 +01:00

Run rustfmt

This commit is contained in:
Yuki Okushi 2020-04-03 16:16:17 +09:00
parent 8f1c0a85cf
commit 046604f286
No known key found for this signature in database
GPG Key ID: B0986C85C0E2DAA1
5 changed files with 42 additions and 49 deletions

View File

@ -98,8 +98,7 @@ mod handlers {
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
let user_info: User = user.into_inner(); let user_info: User = user.into_inner();
let client: Client = let client: Client = db_pool.get().await.map_err(MyError::PoolError)?;
db_pool.get().await.map_err(MyError::PoolError)?;
let new_user = db::add_user(&client, user_info).await?; let new_user = db::add_user(&client, user_info).await?;

View File

@ -1,7 +1,9 @@
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}; use openssl::ssl::{SslConnector, SslMethod};
async fn index(_req: HttpRequest) -> HttpResponse { async fn index(_req: HttpRequest) -> HttpResponse {
let builder = SslConnector::builder(SslMethod::tls()).unwrap(); let builder = SslConnector::builder(SslMethod::tls()).unwrap();
@ -21,21 +23,19 @@ async fn index(_req: HttpRequest) -> HttpResponse {
.await .await
.unwrap(); .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() HttpResponse::Ok().content_type("image/jpeg").body(payload)
.content_type("image/jpeg")
.body(payload)
} }
#[actix_rt::main] #[actix_rt::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
let port = 3000; let port = 3000;
HttpServer::new(|| { HttpServer::new(|| App::new().service(web::resource("/").to(index)))
App::new()
.service(web::resource("/").to(index))
})
.bind(("0.0.0.0", port))? .bind(("0.0.0.0", port))?
.run() .run()
.await .await

View File

@ -19,11 +19,7 @@ async fn again() -> impl Responder {
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
println!("Starting actix-web server"); println!("Starting actix-web server");
HttpServer::new(|| { HttpServer::new(|| App::new().service(index).service(again))
App::new()
.service(index)
.service(again)
})
.bind("0.0.0.0:5000")? .bind("0.0.0.0:5000")?
.run() .run()
.await .await

View File

@ -33,8 +33,7 @@ impl User {
fn products(&self, context: &Context) -> Vec<Product> { fn products(&self, context: &Context) -> Vec<Product> {
let mut conn = context.dbpool.get().unwrap(); let mut conn = context.dbpool.get().unwrap();
conn conn.prep_exec(
.prep_exec(
"select * from product where user_id=:user_id", "select * from product where user_id=:user_id",
params! { params! {
"user_id" => &self.id "user_id" => &self.id

View File

@ -2,7 +2,6 @@ use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
use futures::executor; use futures::executor;
use std::{sync::mpsc, thread}; use std::{sync::mpsc, thread};
#[get("/hello")] #[get("/hello")]
async fn hello() -> &'static str { async fn hello() -> &'static str {
"Hello world!" "Hello world!"