mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31:07 +01:00
Fix/suppress warnings
This commit is contained in:
parent
0f1568bd3c
commit
8f1c0a85cf
@ -1,8 +1,6 @@
|
|||||||
use actix_web::{web, Error as AWError};
|
use actix_web::{web, Error as AWError};
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use futures::{Future, TryFutureExt};
|
use futures::{Future, TryFutureExt};
|
||||||
use r2d2;
|
|
||||||
use r2d2_sqlite;
|
|
||||||
use rusqlite::{Statement, NO_PARAMS};
|
use rusqlite::{Statement, NO_PARAMS};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{thread::sleep, time::Duration};
|
use std::{thread::sleep, time::Duration};
|
||||||
|
@ -22,6 +22,7 @@ mod db;
|
|||||||
use db::{Pool, Queries};
|
use db::{Pool, Queries};
|
||||||
|
|
||||||
/// Version 1: Calls 4 queries in sequential order, as an asynchronous handler
|
/// Version 1: Calls 4 queries in sequential order, as an asynchronous handler
|
||||||
|
#[allow(clippy::eval_order_dependence)] // it's FP?
|
||||||
async fn asyncio_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
|
async fn asyncio_weather(db: web::Data<Pool>) -> Result<HttpResponse, AWError> {
|
||||||
let result = vec![
|
let result = vec![
|
||||||
db::execute(&db, Queries::GetTopTenHottestYears).await?,
|
db::execute(&db, Queries::GetTopTenHottestYears).await?,
|
||||||
|
@ -2,18 +2,18 @@ use actix_web::{web, Error, HttpResponse};
|
|||||||
|
|
||||||
use crate::common::{Part, Product};
|
use crate::common::{Part, Product};
|
||||||
|
|
||||||
pub async fn get_parts(query: web::Query<Option<Part>>) -> Result<HttpResponse, Error> {
|
pub async fn get_parts(_query: web::Query<Option<Part>>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_part(new_part: web::Json<Product>) -> Result<HttpResponse, Error> {
|
pub async fn add_part(_new_part: web::Json<Product>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_part_detail(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
pub async fn get_part_detail(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_part(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
pub async fn remove_part(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,22 @@ use actix_web::{web, Error, HttpResponse};
|
|||||||
use crate::common::{Part, Product};
|
use crate::common::{Part, Product};
|
||||||
|
|
||||||
pub async fn get_products(
|
pub async fn get_products(
|
||||||
query: web::Query<Option<Part>>,
|
_query: web::Query<Option<Part>>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_product(
|
pub async fn add_product(
|
||||||
new_product: web::Json<Product>,
|
_new_product: web::Json<Product>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_product_detail(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
pub async fn get_product_detail(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_product(id: web::Path<String>) -> Result<HttpResponse, Error> {
|
pub async fn remove_product(_id: web::Path<String>) -> Result<HttpResponse, Error> {
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ mod handlers {
|
|||||||
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(|err| MyError::PoolError(err))?;
|
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?;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, client::{Client
|
|||||||
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();
|
||||||
|
|
||||||
let client = Client::build()
|
let client = Client::build()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate actix_web;
|
extern crate actix_web;
|
||||||
|
|
||||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
use actix_web::{App, HttpResponse, HttpServer, Responder};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
async fn index() -> impl Responder {
|
async fn index() -> impl Responder {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use r2d2;
|
|
||||||
use r2d2_mysql::mysql::{Opts, OptsBuilder};
|
use r2d2_mysql::mysql::{Opts, OptsBuilder};
|
||||||
use r2d2_mysql::MysqlConnectionManager;
|
use r2d2_mysql::MysqlConnectionManager;
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use juniper;
|
|
||||||
use mysql::{from_row, params, Error as DBError, Row};
|
use mysql::{from_row, params, Error as DBError, Row};
|
||||||
|
|
||||||
use crate::schemas::root::Context;
|
use crate::schemas::root::Context;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use juniper;
|
|
||||||
use juniper::{FieldError, FieldResult, RootNode};
|
use juniper::{FieldError, FieldResult, RootNode};
|
||||||
use mysql::{from_row, params, Error as DBError, Row};
|
use mysql::{from_row, params, Error as DBError, Row};
|
||||||
|
|
||||||
@ -109,9 +108,9 @@ impl MutationRoot {
|
|||||||
let insert: Result<Option<Row>, DBError> = conn.first_exec(
|
let insert: Result<Option<Row>, DBError> = conn.first_exec(
|
||||||
"INSERT INTO user(id, name, email) VALUES(:id, :name, :email)",
|
"INSERT INTO user(id, name, email) VALUES(:id, :name, :email)",
|
||||||
params! {
|
params! {
|
||||||
"id" => &new_id.to_owned(),
|
"id" => &new_id,
|
||||||
"name" => &user.name.to_owned(),
|
"name" => &user.name,
|
||||||
"email" => &user.email.to_owned(),
|
"email" => &user.email,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -141,9 +140,9 @@ impl MutationRoot {
|
|||||||
let insert: Result<Option<Row>, DBError> = conn.first_exec(
|
let insert: Result<Option<Row>, DBError> = conn.first_exec(
|
||||||
"INSERT INTO product(id, user_id, name, price) VALUES(:id, :user_id, :name, :price)",
|
"INSERT INTO product(id, user_id, name, price) VALUES(:id, :user_id, :name, :price)",
|
||||||
params! {
|
params! {
|
||||||
"id" => &new_id.to_owned(),
|
"id" => &new_id,
|
||||||
"user_id" => &product.user_id.to_owned(),
|
"user_id" => &product.user_id,
|
||||||
"name" => &product.name.to_owned(),
|
"name" => &product.name,
|
||||||
"price" => &product.price.to_owned(),
|
"price" => &product.price.to_owned(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use juniper;
|
|
||||||
use mysql::{from_row, params};
|
use mysql::{from_row, params};
|
||||||
|
|
||||||
use crate::schemas::product::Product;
|
use crate::schemas::product::Product;
|
||||||
@ -33,7 +32,8 @@ 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();
|
||||||
let products = conn
|
|
||||||
|
conn
|
||||||
.prep_exec(
|
.prep_exec(
|
||||||
"select * from product where user_id=:user_id",
|
"select * from product where user_id=:user_id",
|
||||||
params! {
|
params! {
|
||||||
@ -54,7 +54,6 @@ impl User {
|
|||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap()
|
||||||
products
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
// Allow this lint since it's fine to use type directly in the short example.
|
||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
@ -7,7 +10,6 @@ use actix_rt::time::delay_for;
|
|||||||
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::{Future, FutureExt};
|
use futures::{Future, FutureExt};
|
||||||
use serde_json;
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::type_complexity)]
|
||||||
|
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
use futures::future::FutureExt;
|
use futures::future::FutureExt;
|
||||||
|
@ -4,7 +4,6 @@ use std::io;
|
|||||||
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer};
|
||||||
use r2d2::Pool;
|
use r2d2::Pool;
|
||||||
use r2d2_sqlite::SqliteConnectionManager;
|
use r2d2_sqlite::SqliteConnectionManager;
|
||||||
use uuid;
|
|
||||||
|
|
||||||
/// Async request handler. Ddb pool is stored in application state.
|
/// Async request handler. Ddb pool is stored in application state.
|
||||||
async fn index(
|
async fn index(
|
||||||
|
@ -5,7 +5,6 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use actix_web::web::{Bytes, Data, Path};
|
use actix_web::web::{Bytes, Data, Path};
|
||||||
use actix_web::{web, App, Error, HttpResponse, HttpServer, Responder};
|
use actix_web::{web, App, Error, HttpResponse, HttpServer, Responder};
|
||||||
use env_logger;
|
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use tokio::time::{interval_at, Instant};
|
use tokio::time::{interval_at, Instant};
|
||||||
|
@ -23,7 +23,7 @@ async fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
// create a channel
|
// create a channel
|
||||||
let (tx, rx) = mpsc::channel::<()>();
|
let (tx, rx) = mpsc::channel::<()>();
|
||||||
let stopper = tx.clone();
|
let _stopper = tx.clone();
|
||||||
|
|
||||||
let bind = "127.0.0.1:8080";
|
let bind = "127.0.0.1:8080";
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ async fn main() -> io::Result<()> {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
// Create some global state prior to building the server
|
// Create some global state prior to building the server
|
||||||
|
#[allow(clippy::mutex_atomic)] // it's intentional.
|
||||||
let counter1 = web::Data::new(Mutex::new(0usize));
|
let counter1 = web::Data::new(Mutex::new(0usize));
|
||||||
let counter3 = web::Data::new(AtomicUsize::new(0usize));
|
let counter3 = web::Data::new(AtomicUsize::new(0usize));
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ pub async fn index(
|
|||||||
|
|
||||||
let rendered = tmpl
|
let rendered = tmpl
|
||||||
.render("index.html.tera", &context)
|
.render("index.html.tera", &context)
|
||||||
.map_err(|e| error::ErrorInternalServerError(e))?;
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().body(rendered))
|
Ok(HttpResponse::Ok().body(rendered))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use diesel;
|
|
||||||
use diesel::pg::PgConnection;
|
use diesel::pg::PgConnection;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
Loading…
Reference in New Issue
Block a user