From 6d1888e6c3603e4389b7fd7806a029ce06fc722f Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Wed, 19 Nov 2025 19:27:43 +0800 Subject: [PATCH] Fix clippy warnings --- apps/container/src/db.rs | 3 ++- apps/container/src/db/config.rs | 14 +------------- apps/container/src/db/postgresql.rs | 4 ++-- apps/container/src/db/sqlite.rs | 26 ++++++++++---------------- apps/container/src/lib.rs | 2 +- apps/container/src/util.rs | 4 ++-- 6 files changed, 18 insertions(+), 35 deletions(-) diff --git a/apps/container/src/db.rs b/apps/container/src/db.rs index 0f0e2bc..11f7505 100644 --- a/apps/container/src/db.rs +++ b/apps/container/src/db.rs @@ -4,6 +4,7 @@ pub mod sqlite; use async_trait::async_trait; use shared::db_type::DBType; +use std::error::Error; use std::future::Future; use std::{pin::Pin, sync::Arc}; use url::Host; @@ -55,5 +56,5 @@ pub trait DBInfo { where Self: Sized; async fn get_db_container_config_info(&self) -> DBConfigInfoType; - fn get_unstarted_container(&self) -> Result; + fn get_unstarted_container(&self) -> Result>; } diff --git a/apps/container/src/db/config.rs b/apps/container/src/db/config.rs index 7d759c7..1c69d06 100644 --- a/apps/container/src/db/config.rs +++ b/apps/container/src/db/config.rs @@ -1,3 +1,4 @@ +#[derive(Default)] pub struct OptionalContainerConfig { pub image: Option, pub tag: Option, @@ -38,16 +39,3 @@ impl OptionalContainerConfig { } } } - -impl Default for OptionalContainerConfig { - fn default() -> Self { - Self { - image: None, - tag: None, - container_name: None, - database_name: None, - user: None, - password: None, - } - } -} diff --git a/apps/container/src/db/postgresql.rs b/apps/container/src/db/postgresql.rs index 9069b9b..f4343d4 100644 --- a/apps/container/src/db/postgresql.rs +++ b/apps/container/src/db/postgresql.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{error::Error, sync::Arc}; use async_trait::async_trait; use testcontainers::{ @@ -79,7 +79,7 @@ impl DBInfo for PostgreSQLContainer { } } - fn get_unstarted_container(&self) -> Result { + fn get_unstarted_container(&self) -> Result> { Ok( GenericImage::new(self.config.image.clone(), self.config.tag.clone()) .with_exposed_port(5432.tcp()) diff --git a/apps/container/src/db/sqlite.rs b/apps/container/src/db/sqlite.rs index 62b4e2c..cf0dd40 100644 --- a/apps/container/src/db/sqlite.rs +++ b/apps/container/src/db/sqlite.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, sync::Arc}; +use std::{error::Error, path::PathBuf, sync::Arc}; use async_trait::async_trait; @@ -15,6 +15,7 @@ pub struct ContainerConfig { pub absolute_dir_path: PathBuf, } +#[derive(Default)] pub struct OptionalContainerConfig { // Add any optional configuration fields here pub database_name: Option, @@ -36,15 +37,6 @@ impl OptionalContainerConfig { } } -impl Default for OptionalContainerConfig { - fn default() -> Self { - Self { - database_name: None, - absolute_path: None, - } - } -} - pub fn get_default_config() -> ContainerConfig { ContainerConfig { database_name: "sqlite".to_string(), @@ -83,10 +75,10 @@ impl DBInfo for SQLiteContainer { let db_path = self.get_db_absolute_path(); Arc::new(move || { // delete the sqlite database file - if db_path.exists() { - if let Err(e) = std::fs::remove_file(&db_path) { - eprintln!("Failed to delete SQLite database file: {}", e); - } + if db_path.exists() + && let Err(e) = std::fs::remove_file(&db_path) + { + eprintln!("Failed to delete SQLite database file: {}", e); } }) }, @@ -107,7 +99,9 @@ impl DBInfo for SQLiteContainer { } } - fn get_unstarted_container(&self) -> Result { - Err(()) + fn get_unstarted_container(&self) -> Result> { + Err(Box::new(std::io::Error::other( + "SQLite does not use a container", + ))) } } diff --git a/apps/container/src/lib.rs b/apps/container/src/lib.rs index b3a744a..e1b4bc3 100644 --- a/apps/container/src/lib.rs +++ b/apps/container/src/lib.rs @@ -60,7 +60,7 @@ async fn start(config: &Config) { // // write the config files for the api server and database client println!("Writing config files..."); - write_env_files(&db_config); + write_env_files(db_config); println!("Config files written to:"); println!(" - {}", to_absolute_path(API_CONFIG_PATH).display()); println!(" - {}", to_absolute_path(DB_CONFIG_PATH).display()); diff --git a/apps/container/src/util.rs b/apps/container/src/util.rs index 7fa295f..9783ae1 100644 --- a/apps/container/src/util.rs +++ b/apps/container/src/util.rs @@ -31,8 +31,8 @@ pub fn write_env_files(db_config: &DBConfigInfoType) { let api_env_file = EnvFile { file_type: env::EnvFileType::Yaml, - db_type: db_type, - db_url: db_url, + db_type, + db_url, }; let mut db_env_file = api_env_file.clone();