From 98f21fe69e0361db00e5fbceb7a3168dcb926d32 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 11 Sep 2018 09:39:21 -0700 Subject: rust clippy (lint) tweaks --- rust/src/api_entity_crud.rs | 12 ++++++------ rust/src/api_helpers.rs | 3 ++- rust/src/api_server.rs | 12 ++++++------ rust/src/api_wrappers.rs | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs index dd0961d5..4d5caf62 100644 --- a/rust/src/api_entity_crud.rs +++ b/rust/src/api_entity_crud.rs @@ -371,7 +371,7 @@ macro_rules! generic_db_accept_edits_each { macro_rules! generic_db_insert_rev { () => { fn db_insert_rev(&self, conn: &DbConn) -> Result { - Self::db_insert_revs(conn, &vec![self]).map(|id_list| id_list[0]) + Self::db_insert_revs(conn, &[self]).map(|id_list| id_list[0]) } } } @@ -631,7 +631,7 @@ impl EntityCrud for FileEntity { .iter() .map(|r| { Ok(FileReleaseRow { - file_rev: rev_id.clone(), + file_rev: *rev_id, target_release_ident_id: FatCatId::from_str(r)?.to_uuid(), }) }) @@ -646,7 +646,7 @@ impl EntityCrud for FileEntity { let these_url_rows: Vec = url_list .into_iter() .map(|u| FileRevUrlNewRow { - file_rev: rev_id.clone(), + file_rev: *rev_id, rel: u.rel.clone(), url: u.url.clone(), }) @@ -693,7 +693,7 @@ impl EntityCrud for ReleaseEntity { generic_db_insert_rev!(); fn db_create(&self, conn: &DbConn, edit_context: &EditContext) -> Result { - let mut edits = Self::db_create_batch(conn, edit_context, &vec![self])?; + let mut edits = Self::db_create_batch(conn, edit_context, &[self])?; // probably a more elegant way to destroy the vec and take first element Ok(edits.pop().unwrap()) } @@ -750,7 +750,7 @@ impl EntityCrud for ReleaseEntity { rev_ids .iter() .map(|rev_id| Self::IdentNewRow { - rev_id: Some(rev_id.clone()), + rev_id: Some(*rev_id), is_live: edit_context.autoaccept, redirect_id: None, }) @@ -1002,7 +1002,7 @@ impl EntityCrud for ReleaseEntity { .into_iter() .map(|c| { Ok(ReleaseRevAbstractNewRow { - release_rev: rev_id.clone(), + release_rev: *rev_id, abstract_sha1: match c.content { Some(ref content) => Sha1::from(content).hexdigest(), None => match c.sha1.clone() { diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index 6c214223..8ddaf82c 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -117,8 +117,9 @@ impl FatCatId { pub fn to_uuid(&self) -> Uuid { self.0 } + // TODO: just make it u: Uuid and clone (not by ref) pub fn from_uuid(u: &Uuid) -> FatCatId { - FatCatId(u.clone()) + FatCatId(*u) } } diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 076bc085..449196be 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -61,7 +61,7 @@ impl Server { pub fn get_container_handler( &self, id: FatCatId, - _expand: Option, + _expand: &Option, conn: &DbConn, ) -> Result { ContainerEntity::db_get(conn, id) @@ -85,7 +85,7 @@ impl Server { pub fn get_creator_handler( &self, id: FatCatId, - _expand: Option, + _expand: &Option, conn: &DbConn, ) -> Result { CreatorEntity::db_get(conn, id) @@ -129,7 +129,7 @@ impl Server { pub fn get_file_handler( &self, id: FatCatId, - _expand: Option, + _expand: &Option, conn: &DbConn, ) -> Result { FileEntity::db_get(conn, id) @@ -152,7 +152,7 @@ impl Server { pub fn get_release_handler( &self, id: FatCatId, - expand: Option, + expand: &Option, conn: &DbConn, ) -> Result { let mut release = ReleaseEntity::db_get(conn, id)?; @@ -162,7 +162,7 @@ impl Server { release.files = Some(self.get_release_files_handler(id, conn)?); if let Some(ref cid) = release.container_id { release.container = - Some(self.get_container_handler(FatCatId::from_str(&cid)?, None, conn)?); + Some(self.get_container_handler(FatCatId::from_str(&cid)?, &None, conn)?); } } Ok(release) @@ -204,7 +204,7 @@ impl Server { pub fn get_work_handler( &self, id: FatCatId, - _expand: Option, + _expand: &Option, conn: &DbConn, ) -> Result { WorkEntity::db_get(conn, id) diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs index f6425c8c..4d3373e2 100644 --- a/rust/src/api_wrappers.rs +++ b/rust/src/api_wrappers.rs @@ -36,7 +36,7 @@ macro_rules! wrap_entity_handlers { // No transaction for GET let ret = match conn.transaction(|| { let entity_id = FatCatId::from_str(&id)?; - self.$get_handler(entity_id, expand, &conn) + self.$get_handler(entity_id, &expand, &conn) }) { Ok(entity) => $get_resp::FoundEntity(entity), -- cgit v1.2.3