From adb2a13f9e15e13edb2ce201723afd83f79c70b8 Mon Sep 17 00:00:00 2001 From: Lucian Buzzo Date: Sun, 29 Oct 2023 07:52:51 +0000 Subject: [PATCH] fix: resolve linter issues from cargo fmt Signed-off-by: Lucian Buzzo --- quaint/src/connector/mssql.rs | 17 +++++++---------- quaint/src/connector/mysql.rs | 14 +++++--------- quaint/src/connector/postgres.rs | 14 +++++--------- quaint/src/connector/queryable.rs | 4 +--- quaint/src/connector/sqlite.rs | 16 ++++++---------- quaint/src/connector/transaction.rs | 10 +++++----- quaint/src/pooled.rs | 6 +++--- quaint/src/pooled/manager.rs | 2 +- quaint/src/single.rs | 8 ++++++-- 9 files changed, 39 insertions(+), 52 deletions(-) diff --git a/quaint/src/connector/mssql.rs b/quaint/src/connector/mssql.rs index 52bc9c6f5e61..a217721e0019 100644 --- a/quaint/src/connector/mssql.rs +++ b/quaint/src/connector/mssql.rs @@ -11,6 +11,7 @@ use crate::{ use async_trait::async_trait; use connection_string::JdbcString; use futures::lock::Mutex; +use std::sync::Arc; use std::{ convert::TryFrom, fmt, @@ -22,7 +23,6 @@ use std::{ use tiberius::*; use tokio::net::TcpStream; use tokio_util::compat::{Compat, TokioAsyncWriteCompatExt}; -use std::sync::Arc; /// The underlying SQL Server driver. Only available with the `expose-drivers` Cargo feature. #[cfg(feature = "expose-drivers")] @@ -116,17 +116,14 @@ impl TransactionCapable for Mssql { let rollback_stmt = self.rollback_statement(st_depth).await; let opts = TransactionOptions::new( - isolation, + isolation, self.requires_isolation_first(), self.transaction_depth.clone(), commit_stmt, rollback_stmt, ); - - Ok(Box::new( - DefaultTransaction::new(self, &begin_statement, opts).await?, - )) + Ok(Box::new(DefaultTransaction::new(self, &begin_statement, opts).await?)) } } @@ -470,12 +467,12 @@ impl Queryable for Mssql { "BEGIN TRAN".to_string() }; - return ret + return ret; } /// Statement to commit a transaction async fn commit_statement(&self, depth: i32) -> String { - // MSSQL doesn't have a "RELEASE SAVEPOINT" equivalent, so in a nested + // MSSQL doesn't have a "RELEASE SAVEPOINT" equivalent, so in a nested // transaction we just continue onwards let ret = if depth > 1 { " ".to_string() @@ -483,7 +480,7 @@ impl Queryable for Mssql { "COMMIT".to_string() }; - return ret + return ret; } /// Statement to rollback a transaction @@ -495,7 +492,7 @@ impl Queryable for Mssql { "ROLLBACK".to_string() }; - return ret + return ret; } fn requires_isolation_first(&self) -> bool { diff --git a/quaint/src/connector/mysql.rs b/quaint/src/connector/mysql.rs index 68d9cdb95e65..f39e38192a05 100644 --- a/quaint/src/connector/mysql.rs +++ b/quaint/src/connector/mysql.rs @@ -14,6 +14,7 @@ use mysql_async::{ prelude::{Query as _, Queryable as _}, }; use percent_encoding::percent_decode; +use std::sync::Arc; use std::{ borrow::Cow, future::Future, @@ -23,7 +24,6 @@ use std::{ }; use tokio::sync::Mutex; use url::{Host, Url}; -use std::sync::Arc; /// The underlying MySQL driver. Only available with the `expose-drivers` /// Cargo feature. @@ -588,13 +588,9 @@ impl Queryable for Mysql { /// Statement to begin a transaction async fn begin_statement(&self, depth: i32) -> String { let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth); - let ret = if depth > 1 { - savepoint_stmt - } else { - "BEGIN".to_string() - }; + let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() }; - return ret + return ret; } /// Statement to commit a transaction @@ -606,7 +602,7 @@ impl Queryable for Mysql { "COMMIT".to_string() }; - return ret + return ret; } /// Statement to rollback a transaction @@ -618,7 +614,7 @@ impl Queryable for Mysql { "ROLLBACK".to_string() }; - return ret + return ret; } } diff --git a/quaint/src/connector/postgres.rs b/quaint/src/connector/postgres.rs index e1ab15bb9a8e..d79e300e1fe7 100644 --- a/quaint/src/connector/postgres.rs +++ b/quaint/src/connector/postgres.rs @@ -13,6 +13,7 @@ use lru_cache::LruCache; use native_tls::{Certificate, Identity, TlsConnector}; use percent_encoding::percent_decode; use postgres_native_tls::MakeTlsConnector; +use std::sync::Arc; use std::{ borrow::{Borrow, Cow}, fmt::{Debug, Display}, @@ -26,7 +27,6 @@ use tokio_postgres::{ Client, Config, Statement, }; use url::{Host, Url}; -use std::sync::Arc; pub(crate) const DEFAULT_SCHEMA: &str = "public"; @@ -937,13 +937,9 @@ impl Queryable for PostgreSql { /// Statement to begin a transaction async fn begin_statement(&self, depth: i32) -> String { let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth); - let ret = if depth > 1 { - savepoint_stmt - } else { - "BEGIN".to_string() - }; + let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() }; - return ret + return ret; } /// Statement to commit a transaction @@ -955,7 +951,7 @@ impl Queryable for PostgreSql { "COMMIT".to_string() }; - return ret + return ret; } /// Statement to rollback a transaction @@ -967,7 +963,7 @@ impl Queryable for PostgreSql { "ROLLBACK".to_string() }; - return ret + return ret; } } diff --git a/quaint/src/connector/queryable.rs b/quaint/src/connector/queryable.rs index f991e5506d9e..490d7dc6f86b 100644 --- a/quaint/src/connector/queryable.rs +++ b/quaint/src/connector/queryable.rs @@ -137,10 +137,8 @@ macro_rules! impl_default_TransactionCapable { let commit_stmt = self.commit_statement(st_depth).await; let rollback_stmt = self.rollback_statement(st_depth).await; - - let opts = crate::connector::TransactionOptions::new( - isolation, + isolation, self.requires_isolation_first(), depth, commit_stmt, diff --git a/quaint/src/connector/sqlite.rs b/quaint/src/connector/sqlite.rs index 83a3c3d0274a..3b700783aa56 100644 --- a/quaint/src/connector/sqlite.rs +++ b/quaint/src/connector/sqlite.rs @@ -11,9 +11,9 @@ use crate::{ visitor::{self, Visitor}, }; use async_trait::async_trait; +use std::sync::Arc; use std::{convert::TryFrom, path::Path, time::Duration}; use tokio::sync::Mutex; -use std::sync::Arc; pub(crate) const DEFAULT_SQLITE_SCHEMA_NAME: &str = "main"; @@ -141,7 +141,7 @@ impl TryFrom<&str> for Sqlite { let client = Mutex::new(conn); - Ok(Sqlite { + Ok(Sqlite { client, transaction_depth: Arc::new(futures::lock::Mutex::new(0)), }) @@ -260,13 +260,9 @@ impl Queryable for Sqlite { /// Statement to begin a transaction async fn begin_statement(&self, depth: i32) -> String { let savepoint_stmt = format!("SAVEPOINT savepoint{}", depth); - let ret = if depth > 1 { - savepoint_stmt - } else { - "BEGIN".to_string() - }; + let ret = if depth > 1 { savepoint_stmt } else { "BEGIN".to_string() }; - return ret + return ret; } /// Statement to commit a transaction @@ -278,7 +274,7 @@ impl Queryable for Sqlite { "COMMIT".to_string() }; - return ret + return ret; } /// Statement to rollback a transaction @@ -290,7 +286,7 @@ impl Queryable for Sqlite { "ROLLBACK".to_string() }; - return ret + return ret; } } diff --git a/quaint/src/connector/transaction.rs b/quaint/src/connector/transaction.rs index e6caa01b0e2a..fd857c935653 100644 --- a/quaint/src/connector/transaction.rs +++ b/quaint/src/connector/transaction.rs @@ -4,10 +4,10 @@ use crate::{ error::{Error, ErrorKind}, }; use async_trait::async_trait; -use metrics::{decrement_gauge, increment_gauge}; -use std::{fmt, str::FromStr}; use futures::lock::Mutex; +use metrics::{decrement_gauge, increment_gauge}; use std::sync::Arc; +use std::{fmt, str::FromStr}; extern crate metrics as metrics; @@ -58,8 +58,8 @@ impl<'a> DefaultTransaction<'a> { begin_stmt: &str, tx_opts: TransactionOptions, ) -> crate::Result> { - let this = Self { - inner, + let this = Self { + inner, depth: tx_opts.depth, commit_stmt: tx_opts.commit_stmt, rollback_stmt: tx_opts.rollback_stmt, @@ -222,7 +222,7 @@ impl FromStr for IsolationLevel { } impl TransactionOptions { pub fn new( - isolation_level: Option, + isolation_level: Option, isolation_first: bool, depth: Arc>, commit_stmt: String, diff --git a/quaint/src/pooled.rs b/quaint/src/pooled.rs index aec229b744dc..458a3412ecec 100644 --- a/quaint/src/pooled.rs +++ b/quaint/src/pooled.rs @@ -500,9 +500,9 @@ impl Quaint { } }; - Ok(PooledConnection { - inner, - transaction_depth: Arc::new(futures::lock::Mutex::new(0)) + Ok(PooledConnection { + inner, + transaction_depth: Arc::new(futures::lock::Mutex::new(0)), }) } diff --git a/quaint/src/pooled/manager.rs b/quaint/src/pooled/manager.rs index 27367961cbe5..e1e028bb0ef5 100644 --- a/quaint/src/pooled/manager.rs +++ b/quaint/src/pooled/manager.rs @@ -10,8 +10,8 @@ use crate::{ error::Error, }; use async_trait::async_trait; -use mobc::{Connection as MobcPooled, Manager}; use futures::lock::Mutex; +use mobc::{Connection as MobcPooled, Manager}; use std::sync::Arc; /// A connection from the pool. Implements diff --git a/quaint/src/single.rs b/quaint/src/single.rs index da173321ff51..e5c6175fbbed 100644 --- a/quaint/src/single.rs +++ b/quaint/src/single.rs @@ -7,8 +7,8 @@ use crate::{ connector::{self, impl_default_TransactionCapable, ConnectionInfo, IsolationLevel, Queryable, TransactionCapable}, }; use async_trait::async_trait; -use std::{fmt, sync::Arc}; use futures::lock::Mutex; +use std::{fmt, sync::Arc}; #[cfg(feature = "sqlite")] use std::convert::TryFrom; @@ -165,7 +165,11 @@ impl Quaint { let connection_info = Arc::new(ConnectionInfo::from_url(url_str)?); Self::log_start(&connection_info); - Ok(Self { inner, connection_info, transaction_depth: Arc::new(Mutex::new(0)) }) + Ok(Self { + inner, + connection_info, + transaction_depth: Arc::new(Mutex::new(0)), + }) } #[cfg(feature = "sqlite")]