From 8a0ddade93ac620692682931b377a46a30d8ffbd Mon Sep 17 00:00:00 2001 From: Alex Ted Date: Tue, 21 Jan 2025 20:41:27 +0300 Subject: [PATCH] feat: linter check fixed --- Cargo.lock | 114 +++++++++++++++++-- databases/diesel-async/src/actions.rs | 34 +++--- databases/diesel-async/src/main.rs | 28 ++--- databases/diesel-async/src/models.rs | 4 +- graphql/async-graphql/src/star_wars/model.rs | 4 +- middleware/http-to-https/src/main.rs | 4 +- 6 files changed, 137 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f177797..c286f7ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,7 +329,7 @@ dependencies = [ "actix-utils", "futures-core", "futures-util", - "mio", + "mio 1.0.3", "socket2", "tokio", "tracing", @@ -1708,6 +1708,18 @@ dependencies = [ "log", ] +[[package]] +name = "bb8" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89aabfae550a5c44b43ab941844ffcd2e993cb6900b342debf59e9ea74acdb8" +dependencies = [ + "async-trait", + "futures-util", + "parking_lot", + "tokio", +] + [[package]] name = "bigdecimal" version = "0.3.1" @@ -1997,7 +2009,7 @@ dependencies = [ "env_logger", "eyre", "log", - "notify", + "notify 6.1.1", "rustls 0.23.20", "rustls-pemfile 2.2.0", "tokio", @@ -2553,6 +2565,18 @@ dependencies = [ "uuid", ] +[[package]] +name = "db-diesel-async" +version = "1.0.0" +dependencies = [ + "actix-web", + "diesel", + "diesel-async", + "dotenvy", + "serde", + "uuid", +] + [[package]] name = "db-mongo" version = "1.0.0" @@ -2748,6 +2772,21 @@ dependencies = [ "uuid", ] +[[package]] +name = "diesel-async" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51a307ac00f7c23f526a04a77761a0519b9f0eb2838ebf5b905a58580095bdcb" +dependencies = [ + "async-trait", + "bb8", + "diesel", + "futures-util", + "scoped-futures", + "tokio", + "tokio-postgres", +] + [[package]] name = "diesel_derives" version = "2.2.3" @@ -2976,7 +3015,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4254,6 +4293,17 @@ dependencies = [ "serde", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + [[package]] name = "inotify" version = "0.10.2" @@ -4635,7 +4685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -4956,7 +5006,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "311916ed8368c1fe24ef7b6b9d15f8f69c48c755fe5e9cc609687f2a13dbb8fb" dependencies = [ "minijinja", - "notify", + "notify 7.0.0", ] [[package]] @@ -4983,6 +5033,18 @@ dependencies = [ "adler2", ] +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "mio" version = "1.0.3" @@ -5272,6 +5334,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.6.0", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify 0.9.6", + "kqueue", + "libc", + "log", + "mio 0.8.11", + "walkdir", + "windows-sys 0.48.0", +] + [[package]] name = "notify" version = "7.0.0" @@ -5281,11 +5362,11 @@ dependencies = [ "bitflags 2.6.0", "filetime", "fsevent-sys", - "inotify", + "inotify 0.10.2", "kqueue", "libc", "log", - "mio", + "mio 1.0.3", "notify-types", "walkdir", "windows-sys 0.52.0", @@ -6156,7 +6237,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6625,7 +6706,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -6861,6 +6942,15 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "scoped-futures" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b24aae2d0636530f359e9d5ef0c04669d11c5e756699b27a6a6d845d8329091" +dependencies = [ + "pin-project-lite", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -7744,7 +7834,7 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8082,7 +8172,7 @@ dependencies = [ "backtrace", "bytes", "libc", - "mio", + "mio 1.0.3", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -9216,7 +9306,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/databases/diesel-async/src/actions.rs b/databases/diesel-async/src/actions.rs index 303d6284..17ecb31d 100644 --- a/databases/diesel-async/src/actions.rs +++ b/databases/diesel-async/src/actions.rs @@ -27,27 +27,27 @@ pub async fn find_item_by_uid( Ok(item) } - /// Run query using Diesel to insert a new database row and return the result. +/// Run query using Diesel to insert a new database row and return the result. pub async fn insert_new_item( conn: &mut AsyncPgConnection, nm: &str, // prevent collision with `name` column imported inside the function ) -> Result { - // It is common when using Diesel with Actix Web to import schema-related - // modules inside a function's scope (rather than the normal module's scope) - // to prevent import collisions and namespace pollution. - use crate::schema::items::dsl::*; - - let new_item = models::Item { - id: Uuid::new_v7(Timestamp::now(NoContext)), - name: nm.to_owned(), + // It is common when using Diesel with Actix Web to import schema-related + // modules inside a function's scope (rather than the normal module's scope) + // to prevent import collisions and namespace pollution. + use crate::schema::items::dsl::*; + + let new_item = models::Item { + id: Uuid::new_v7(Timestamp::now(NoContext)), + name: nm.to_owned(), }; - + let item = diesel::insert_into(items) - .values(&new_item) - .returning(models::Item::as_returning()) - .get_result(conn) - .await - .expect("Error inserting person"); - + .values(&new_item) + .returning(models::Item::as_returning()) + .get_result(conn) + .await + .expect("Error inserting person"); + Ok(item) -} \ No newline at end of file +} diff --git a/databases/diesel-async/src/main.rs b/databases/diesel-async/src/main.rs index cd69324b..84d36691 100644 --- a/databases/diesel-async/src/main.rs +++ b/databases/diesel-async/src/main.rs @@ -1,19 +1,16 @@ #[macro_use] extern crate diesel; -use std::env::VarError; - use actix_web::{error, get, post, web, App, HttpResponse, HttpServer, Responder}; -use diesel_async::pooled_connection::{bb8::Pool, AsyncDieselConnectionManager, PoolError}; +use diesel_async::pooled_connection::{bb8::Pool, AsyncDieselConnectionManager}; use diesel_async::AsyncPgConnection; use dotenvy::dotenv; use std::{env, io}; -use thiserror::Error as ThisError; use uuid::Uuid; -pub mod actions; -pub mod models; -pub mod schema; +mod actions; +mod models; +mod schema; type DbPool = Pool; @@ -35,9 +32,9 @@ async fn get_item( .expect("Couldn't get db connection from the pool"); let item = actions::find_item_by_uid(&mut conn, item_uid) - .await - // map diesel query errors to a 500 error response - .map_err(error::ErrorInternalServerError)?; + .await + // map diesel query errors to a 500 error response + .map_err(error::ErrorInternalServerError)?; Ok(match item { // item was found; return 200 response with JSON formatted item object @@ -58,16 +55,15 @@ async fn add_item( pool: web::Data, form: web::Json, ) -> actix_web::Result { - let mut conn = pool .get() .await .expect("Couldn't get db connection from the pool"); let item = actions::insert_new_item(&mut conn, &form.name) - .await - // map diesel query errors to a 500 error response - .map_err(error::ErrorInternalServerError)?; + .await + // map diesel query errors to a 500 error response + .map_err(error::ErrorInternalServerError)?; // item was added successfully; return 201 response with new item info Ok(HttpResponse::Created().json(item)) @@ -76,7 +72,7 @@ async fn add_item( #[actix_web::main] async fn main() -> io::Result<()> { dotenv().ok(); - + let db_url = env::var("DATABASE_URL").expect("Env var `DATABASE_URL` not set"); let mgr = AsyncDieselConnectionManager::::new(db_url); @@ -88,7 +84,7 @@ async fn main() -> io::Result<()> { .service(add_item) .service(get_item) }) - .bind(("127.0.0.1", 5000))? + .bind(("127.0.0.1", 8080))? .run() .await } diff --git a/databases/diesel-async/src/models.rs b/databases/diesel-async/src/models.rs index e8cc61bf..6d08565f 100644 --- a/databases/diesel-async/src/models.rs +++ b/databases/diesel-async/src/models.rs @@ -1,6 +1,6 @@ +use super::schema::items; use serde::{Deserialize, Serialize}; use uuid::Uuid; -use super::schema::items; /// Item details. #[derive(Debug, Clone, Serialize, Deserialize, Queryable, Selectable, Insertable)] @@ -20,6 +20,6 @@ impl NewItem { /// Constructs new item details from name. #[cfg(test)] // only needed in tests pub fn new(name: impl Into) -> Self { - Self { name: name.into(), ..Default::default() } + Self { name: name.into() } } } diff --git a/graphql/async-graphql/src/star_wars/model.rs b/graphql/async-graphql/src/star_wars/model.rs index c15be5a8..ad0ce124 100644 --- a/graphql/async-graphql/src/star_wars/model.rs +++ b/graphql/async-graphql/src/star_wars/model.rs @@ -22,7 +22,7 @@ pub struct Human<'a>(&'a StarWarsChar); /// A humanoid creature in the Star Wars universe. #[Object] -impl<'a> Human<'a> { +impl Human<'_> { /// The id of the human. async fn id(&self) -> &str { self.0.id @@ -63,7 +63,7 @@ pub struct Droid<'a>(&'a StarWarsChar); /// A mechanical creature in the Star Wars universe. #[Object] -impl<'a> Droid<'a> { +impl Droid<'_> { /// The id of the droid. async fn id(&self) -> &str { self.0.id diff --git a/middleware/http-to-https/src/main.rs b/middleware/http-to-https/src/main.rs index 8355d4c7..a7f06556 100644 --- a/middleware/http-to-https/src/main.rs +++ b/middleware/http-to-https/src/main.rs @@ -52,11 +52,11 @@ async fn main() -> std::io::Result<()> { Either::Left(srv.call(sreq).map(|res| res)) } else { println!("An http request has arrived here, i will redirect it to use https"); - return Either::Right(future::ready(Ok(sreq.into_response( + Either::Right(future::ready(Ok(sreq.into_response( HttpResponse::MovedPermanently() .append_header((http::header::LOCATION, url)) .finish(), - )))); + )))) } }) .service(index)