From 4cf0da7b60b68027f29a49a8a518f266c3084463 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 30 Mar 2022 10:58:03 -0400 Subject: [PATCH] Clippy fixes. --- crates/apub/src/collections/community_moderators.rs | 4 ++-- crates/apub/src/collections/community_outbox.rs | 2 +- crates/apub/src/fetcher/webfinger.rs | 3 +-- crates/apub/src/objects/comment.rs | 2 +- crates/apub/src/objects/community.rs | 2 +- crates/apub/src/objects/instance.rs | 2 +- crates/apub/src/objects/person.rs | 2 +- crates/apub/src/objects/post.rs | 2 +- crates/apub/src/objects/private_message.rs | 2 +- crates/db_schema/src/lib.rs | 4 ++-- crates/db_views/src/comment_report_view.rs | 6 +----- crates/db_views/src/post_report_view.rs | 2 +- crates/routes/src/feeds.rs | 2 +- crates/routes/src/webfinger.rs | 3 +-- crates/utils/src/request.rs | 3 +-- src/scheduled_tasks.rs | 2 +- 16 files changed, 18 insertions(+), 25 deletions(-) diff --git a/crates/apub/src/collections/community_moderators.rs b/crates/apub/src/collections/community_moderators.rs index 52825482..b0182bdf 100644 --- a/crates/apub/src/collections/community_moderators.rs +++ b/crates/apub/src/collections/community_moderators.rs @@ -41,7 +41,7 @@ impl ApubObject for ApubCommunityModerators { CommunityModeratorView::for_community(conn, cid) }) .await??; - Ok(Some(ApubCommunityModerators { 0: moderators })) + Ok(Some(ApubCommunityModerators(moderators))) } else { Ok(None) } @@ -131,7 +131,7 @@ impl ApubObject for ApubCommunityModerators { } // This return value is unused, so just set an empty vec - Ok(ApubCommunityModerators { 0: vec![] }) + Ok(ApubCommunityModerators(Vec::new())) } type DbType = (); diff --git a/crates/apub/src/collections/community_outbox.rs b/crates/apub/src/collections/community_outbox.rs index 3b4c8534..f3303406 100644 --- a/crates/apub/src/collections/community_outbox.rs +++ b/crates/apub/src/collections/community_outbox.rs @@ -116,7 +116,7 @@ impl ApubObject for ApubCommunityOutbox { } // This return value is unused, so just set an empty vec - Ok(ApubCommunityOutbox { 0: vec![] }) + Ok(ApubCommunityOutbox(Vec::new())) } type DbType = (); diff --git a/crates/apub/src/fetcher/webfinger.rs b/crates/apub/src/fetcher/webfinger.rs index 918e1de0..e2370c32 100644 --- a/crates/apub/src/fetcher/webfinger.rs +++ b/crates/apub/src/fetcher/webfinger.rs @@ -73,8 +73,7 @@ where false } }) - .map(|l| l.href.clone()) - .flatten() + .filter_map(|l| l.href.clone()) .collect(); for l in links { let object = ObjectId::::new(l) diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index bc8cacea..c622c14d 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -47,7 +47,7 @@ impl Deref for ApubComment { impl From for ApubComment { fn from(c: Comment) -> Self { - ApubComment { 0: c } + ApubComment(c) } } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index eb9cb218..bbb239cb 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -41,7 +41,7 @@ impl Deref for ApubCommunity { impl From for ApubCommunity { fn from(c: Community) -> Self { - ApubCommunity { 0: c } + ApubCommunity(c) } } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 9968b81e..af75812d 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -37,7 +37,7 @@ impl Deref for ApubSite { impl From for ApubSite { fn from(s: Site) -> Self { - ApubSite { 0: s } + ApubSite(s) } } diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index a903d5a6..a6133ed4 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -47,7 +47,7 @@ impl Deref for ApubPerson { impl From for ApubPerson { fn from(p: DbPerson) -> Self { - ApubPerson { 0: p } + ApubPerson(p) } } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index d5309dc1..dbea0349 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -50,7 +50,7 @@ impl Deref for ApubPost { impl From for ApubPost { fn from(p: Post) -> Self { - ApubPost { 0: p } + ApubPost(p) } } diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 6f445184..04974b80 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -40,7 +40,7 @@ impl Deref for ApubPrivateMessage { impl From for ApubPrivateMessage { fn from(pm: PrivateMessage) -> Self { - ApubPrivateMessage { 0: pm } + ApubPrivateMessage(pm) } } diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 5388d37c..724fffcd 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -65,11 +65,11 @@ pub enum SearchType { } pub fn from_opt_str_to_opt_enum(opt: &Option) -> Option { - opt.as_ref().map(|t| T::from_str(t).ok()).flatten() + opt.as_ref().and_then(|t| T::from_str(t).ok()) } pub fn fuzzy_search(q: &str) -> String { - let replaced = q.replace("%", "\\%").replace("_", "\\_").replace(" ", "%"); + let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%"); format!("%{}%", replaced) } diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 68c00027..63701db9 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -120,11 +120,7 @@ impl CommentReportView { )) .first::(conn)?; - let my_vote = if comment_like.is_none() { - None - } else { - comment_like - }; + let my_vote = comment_like; Ok(Self { comment_report, diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index e8532a91..66341d67 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -111,7 +111,7 @@ impl PostReportView { )) .first::(conn)?; - let my_vote = if post_like.is_none() { None } else { post_like }; + let my_vote = post_like; Ok(Self { post_report, diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 8fee2395..bfe49fbd 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -373,7 +373,7 @@ fn build_item( i.guid(guid); i.link(url.to_owned()); // TODO add images - let html = markdown_to_html(&content.to_string()); + let html = markdown_to_html(content); i.description(html); Ok(i.build()) } diff --git a/crates/routes/src/webfinger.rs b/crates/routes/src/webfinger.rs index b3155379..a95902b2 100644 --- a/crates/routes/src/webfinger.rs +++ b/crates/routes/src/webfinger.rs @@ -39,8 +39,7 @@ async fn get_webfinger_response( .settings() .webfinger_regex() .captures(&info.resource) - .map(|c| c.get(1)) - .flatten() + .and_then(|c| c.get(1)) .context(location_info!())? .as_str() .to_string(); diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index 1e4f4bf3..c0593ffa 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -138,8 +138,7 @@ fn html_to_site_metadata(html_bytes: &[u8]) -> Result .opengraph .images .get(0) - .map(|ogo| Url::parse(&ogo.url).ok()) - .flatten(); + .and_then(|ogo| Url::parse(&ogo.url).ok()); let title = og_title.or(page_title); let description = og_description.or(page_description); diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 23c4fdc4..30e553b5 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -98,7 +98,7 @@ fn active_counts(conn: &PgConnection) { fn update_banned_when_expired(conn: &PgConnection) { info!("Updating banned column if it expires ..."); let update_ban_expires_stmt = - format!("update person set banned = false where banned = true and ban_expires < now()"); + "update person set banned = false where banned = true and ban_expires < now()"; sql_query(update_ban_expires_stmt) .execute(conn) .expect("update banned when expires"); -- 2.44.1