vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit c47d9f65937df1d2d7f4f7b9a679a887a3d182bc
parent 5399ee8208e0d3a3e5b06c7d3cc08300a2ea8881
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Mon,  9 Jan 2023 19:54:25 +0100

Fix some lints: explicit Arc::clone, and unnecessary return after unreachable!

Diffstat:
Msrc/db/mod.rs | 25+++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/db/mod.rs b/src/db/mod.rs @@ -75,12 +75,10 @@ macro_rules! generate_connections { #[cfg($name)] impl CustomizeConnection<$ty, diesel::r2d2::Error> for DbConnOptions { fn on_acquire(&self, conn: &mut $ty) -> Result<(), diesel::r2d2::Error> { - (|| { - if !self.init_stmts.is_empty() { - conn.batch_execute(&self.init_stmts)?; - } - Ok(()) - })().map_err(diesel::r2d2::Error::QueryError) + if !self.init_stmts.is_empty() { + conn.batch_execute(&self.init_stmts).map_err(diesel::r2d2::Error::QueryError)?; + } + Ok(()) } })+ @@ -97,7 +95,7 @@ macro_rules! generate_connections { impl Drop for DbConn { fn drop(&mut self) { - let conn = self.conn.clone(); + let conn = Arc::clone(&self.conn); let permit = self.permit.take(); // Since connection can't be on the stack in an async fn during an @@ -143,21 +141,20 @@ macro_rules! generate_connections { })) .build(manager) .map_res("Failed to create pool")?; - return Ok(DbPool { + Ok(DbPool { pool: Some(DbPoolInner::$name(pool)), semaphore: Arc::new(Semaphore::new(CONFIG.database_max_conns() as usize)), - }); + }) } #[cfg(not($name))] - #[allow(unreachable_code)] - return unreachable!("Trying to use a DB backend when it's feature is disabled"); + unreachable!("Trying to use a DB backend when it's feature is disabled") }, )+ } } // Get a connection from the pool pub async fn get(&self) -> Result<DbConn, Error> { let duration = Duration::from_secs(CONFIG.database_timeout()); - let permit = match timeout(duration, self.semaphore.clone().acquire_owned()).await { + let permit = match timeout(duration, Arc::clone(&self.semaphore).acquire_owned()).await { Ok(p) => p.expect("Semaphore should be open"), Err(_) => { err!("Timeout waiting for database connection"); @@ -170,10 +167,10 @@ macro_rules! generate_connections { let pool = p.clone(); let c = run_blocking(move || pool.get_timeout(duration)).await.map_res("Error retrieving connection from pool")?; - return Ok(DbConn { + Ok(DbConn { conn: Arc::new(Mutex::new(Some(DbConnInner::$name(c)))), permit: Some(permit) - }); + }) }, )+ } }