1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +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> {
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?;

View File

@ -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
}

View File

@ -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
}
HttpServer::new(|| App::new().service(index).service(again))
.bind("0.0.0.0:5000")?
.run()
.await
}

View File

@ -33,27 +33,26 @@ impl User {
fn products(&self, context: &Context) -> Vec<Product> {
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()
}
}

View File

@ -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!"