diff --git a/src/auth.rs b/src/auth.rs index 2b38c14e..57ec50e5 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -29,9 +29,7 @@ impl AuthorizationService { let claims = UserClaims { user, exp: exp_date }; - let token = encode(&Header::default(), &claims, &EncodingKey::from_secret(key)).unwrap(); - - token + encode(&Header::default(), &claims, &EncodingKey::from_secret(key)).unwrap() } pub async fn verify_jwt(&self, token: &str) -> Result { diff --git a/src/config.rs b/src/config.rs index 00d390dc..110d7fb2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -135,9 +135,9 @@ impl Configuration { eprintln!("Creating config file.."); let config = Configuration::default(); let _ = config.save_to_file().await; - return Err(ConfigError::Message(format!( - "Please edit the config.TOML in the root folder and restart the tracker." - ))); + return Err(ConfigError::Message( + "Please edit the config.TOML in the root folder and restart the tracker.".to_string(), + )); } let torrust_config: TorrustConfig = match config.try_into() { diff --git a/src/databases/database.rs b/src/databases/database.rs index c4dad043..0f06f702 100644 --- a/src/databases/database.rs +++ b/src/databases/database.rs @@ -11,7 +11,7 @@ use crate::models::tracker_key::TrackerKey; use crate::models::user::{User, UserAuthentication, UserCompact, UserProfile}; /// Database drivers. -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub enum DatabaseDriver { Sqlite3, Mysql, diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index 75afe1c8..8c411eec 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -323,7 +323,7 @@ impl Database for MysqlDatabase { i += 1; } } - if category_filters.len() > 0 { + if !category_filters.is_empty() { format!( "INNER JOIN torrust_categories tc ON tt.category_id = tc.category_id AND ({}) ", category_filters diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index 44e297a2..354e7bdf 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -318,7 +318,7 @@ impl Database for SqliteDatabase { i += 1; } } - if category_filters.len() > 0 { + if !category_filters.is_empty() { format!( "INNER JOIN torrust_categories tc ON tt.category_id = tc.category_id AND ({}) ", category_filters diff --git a/src/errors.rs b/src/errors.rs index 6f5ee0a2..24a413e6 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -10,7 +10,7 @@ use crate::databases::database::DatabaseError; pub type ServiceResult = Result; -#[derive(Debug, Display, PartialEq, Error)] +#[derive(Debug, Display, PartialEq, Eq, Error)] #[allow(dead_code)] pub enum ServiceError { #[display(fmt = "internal server error")] @@ -182,7 +182,6 @@ impl ResponseError for ServiceError { HttpResponseBuilder::new(self.status_code()) .append_header((header::CONTENT_TYPE, "application/json; charset=UTF-8")) .body(serde_json::to_string(&ErrorToResponse { error: self.to_string() }).unwrap()) - .into() } } diff --git a/src/models/torrent.rs b/src/models/torrent.rs index 4adab162..9063c7f3 100644 --- a/src/models/torrent.rs +++ b/src/models/torrent.rs @@ -4,7 +4,7 @@ use crate::models::torrent_file::Torrent; use crate::routes::torrent::CreateTorrent; #[allow(dead_code)] -#[derive(Debug, PartialEq, Serialize, Deserialize, sqlx::FromRow)] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, sqlx::FromRow)] pub struct TorrentListing { pub torrent_id: i64, pub uploader: String, diff --git a/src/models/torrent_file.rs b/src/models/torrent_file.rs index 98cd4c00..581d73a8 100644 --- a/src/models/torrent_file.rs +++ b/src/models/torrent_file.rs @@ -6,10 +6,10 @@ use sha1::{Digest, Sha1}; use crate::config::Configuration; use crate::utils::hex::{bytes_to_hex, hex_to_bytes}; -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct TorrentNode(String, i64); -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct TorrentFile { pub path: Vec, pub length: i64, @@ -17,7 +17,7 @@ pub struct TorrentFile { pub md5sum: Option, } -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)] pub struct TorrentInfo { pub name: String, #[serde(default)] @@ -160,7 +160,7 @@ impl Torrent { pub fn file_size(&self) -> i64 { if self.info.length.is_some() { - return self.info.length.unwrap(); + self.info.length.unwrap() } else { match &self.info.files { None => 0, @@ -176,7 +176,7 @@ impl Torrent { } } -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct DbTorrentFile { pub path: Option, pub length: i64, @@ -184,7 +184,7 @@ pub struct DbTorrentFile { pub md5sum: Option, } -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct DbTorrentInfo { pub name: String, pub pieces: String, @@ -194,7 +194,7 @@ pub struct DbTorrentInfo { pub root_hash: i64, } -#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] +#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, sqlx::FromRow)] pub struct DbTorrentAnnounceUrl { pub tracker_url: String, } diff --git a/src/models/user.rs b/src/models/user.rs index 53d0a4e0..f64b88b4 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -13,7 +13,7 @@ pub struct UserAuthentication { pub password_hash: String, } -#[derive(Debug, PartialEq, Serialize, Deserialize, Clone, sqlx::FromRow)] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone, sqlx::FromRow)] pub struct UserProfile { pub user_id: i64, pub username: String, diff --git a/src/routes/category.rs b/src/routes/category.rs index 8bcd0348..defca8a8 100644 --- a/src/routes/category.rs +++ b/src/routes/category.rs @@ -57,7 +57,7 @@ pub async fn delete_category( return Err(ServiceError::Unauthorized); } - let _ = app_data.database.delete_category(&payload.name).await?; + app_data.database.delete_category(&payload.name).await?; Ok(HttpResponse::Ok().json(OkResponse { data: payload.name.clone(), diff --git a/src/routes/torrent.rs b/src/routes/torrent.rs index 5d87e8b2..41074b4b 100644 --- a/src/routes/torrent.rs +++ b/src/routes/torrent.rs @@ -250,12 +250,12 @@ pub async fn update_torrent( // update torrent title if let Some(title) = &payload.title { - let _res = app_data.database.update_torrent_title(torrent_id, title).await?; + app_data.database.update_torrent_title(torrent_id, title).await?; } // update torrent description if let Some(description) = &payload.description { - let _res = app_data.database.update_torrent_description(torrent_id, description).await?; + app_data.database.update_torrent_description(torrent_id, description).await?; } let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; @@ -278,7 +278,7 @@ pub async fn delete_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceRe // needed later for removing torrent from tracker whitelist let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; - let _res = app_data.database.delete_torrent(torrent_id).await?; + app_data.database.delete_torrent(torrent_id).await?; // remove info_hash from tracker whitelist let _ = app_data @@ -344,7 +344,7 @@ async fn get_torrent_request_from_payload(mut payload: Multipart) -> Result title = parsed_data.to_string(), diff --git a/src/routes/user.rs b/src/routes/user.rs index ed6b1564..6b535bc6 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -179,7 +179,7 @@ pub async fn verify_token(payload: web::Json, app_data: WebAppData) -> Se let _claims = app_data.auth.verify_jwt(&payload.token).await?; Ok(HttpResponse::Ok().json(OkResponse { - data: format!("Token is valid."), + data: "Token is valid.".to_string(), })) } @@ -256,7 +256,7 @@ pub async fn ban_user(req: HttpRequest, app_data: WebAppData) -> ServiceResult) -> Result) { - let add_test_user_result = add_test_user(&db).await; + let add_test_user_result = add_test_user(db).await; assert!(add_test_user_result.is_ok()); @@ -49,7 +49,7 @@ pub async fn it_can_add_a_user(db: &Box) { user_id: inserted_user_id, username: TEST_USER_USERNAME.to_string(), email: TEST_USER_EMAIL.to_string(), - email_verified: returned_user_profile.email_verified.clone(), + email_verified: returned_user_profile.email_verified, bio: returned_user_profile.bio.clone(), avatar: returned_user_profile.avatar.clone() } @@ -57,7 +57,7 @@ pub async fn it_can_add_a_user(db: &Box) { } pub async fn it_can_add_a_torrent_category(db: &Box) { - let add_test_torrent_category_result = add_test_torrent_category(&db).await; + let add_test_torrent_category_result = add_test_torrent_category(db).await; assert!(add_test_torrent_category_result.is_ok()); @@ -72,8 +72,8 @@ pub async fn it_can_add_a_torrent_category(db: &Box) { pub async fn it_can_add_a_torrent_and_tracker_stats_to_that_torrent(db: &Box) { // set pre-conditions - let user_id = add_test_user(&db).await.expect("add_test_user failed."); - let torrent_category_id = add_test_torrent_category(&db) + let user_id = add_test_user(db).await.expect("add_test_user failed."); + let torrent_category_id = add_test_torrent_category(db) .await .expect("add_test_torrent_category failed.");