From 6491841160c66d4b191f1c5d77a578ceee8b94cc Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Fri, 22 Dec 2023 14:32:20 +0900 Subject: [PATCH] refactor according to clippy's suggests --- src/main.rs | 3 ++- src/ogp.rs | 45 ++++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 67ab152..192d9f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -203,7 +203,8 @@ async fn main() -> Result<(), Box> { let rss_url = std::env::var("RSS_URL")?; let bsky_id = std::env::var("BSKY_ID")?; let bsky_password = std::env::var("BSKY_PASSWORD")?; - let bsky_api_url = std::env::var("BSKY_API_URL").unwrap_or_else(|_| BSKY_API_DEFAULT_URL.into()); + let bsky_api_url = + std::env::var("BSKY_API_URL").unwrap_or_else(|_| BSKY_API_DEFAULT_URL.into()); let bsky_agent = AtpAgent::new( ReqwestClient::new(bsky_api_url), diff --git a/src/ogp.rs b/src/ogp.rs index deabbef..9c6022e 100644 --- a/src/ogp.rs +++ b/src/ogp.rs @@ -21,7 +21,7 @@ pub struct Ogp { // find a `content` attribute that has a specified `property` attribute, // e.g. find_property_content("og:image") will return the `content` (i.e. url) of -fn find_property_content(attrs: &Vec, property: &str) -> Option { +fn find_property(attrs: &[Attribute], property: &str) -> Option { if attrs .iter() .any(|a| a.name.local == NAME_PROPERTY && a.value.to_lowercase() == property) @@ -42,30 +42,25 @@ impl TokenSink for Ogp { type Handle = (); fn process_token(&mut self, token: Token, _line_number: u64) -> TokenSinkResult<()> { - match token { - Token::TagToken(Tag { - kind: TagKind::StartTag, - name, - self_closing: _, - attrs, - }) => match name { - NAME_META => { - if let Some(og_title) = find_property_content(&attrs, "og:title") { - self.og_title = Some(og_title); - } - if let Some(og_description) = find_property_content(&attrs, "og:description") { - self.og_description = Some(og_description); - } - if let Some(og_url) = find_property_content(&attrs, "og:url") { - self.og_url = Some(og_url); - } - if let Some(og_image) = find_property_content(&attrs, "og:image") { - self.og_image = Some(og_image); - } - } - _ => {} - }, - _ => {} + if let Token::TagToken(Tag { + kind: TagKind::StartTag, + name: NAME_META, + self_closing: _, + attrs, + }) = token + { + if let Some(og_title) = find_property(&attrs, "og:title") { + self.og_title = Some(og_title); + } + if let Some(og_desc) = find_property(&attrs, "og:description") { + self.og_description = Some(og_desc); + } + if let Some(og_url) = find_property(&attrs, "og:url") { + self.og_url = Some(og_url); + } + if let Some(og_image) = find_property(&attrs, "og:image") { + self.og_image = Some(og_image); + } } TokenSinkResult::Continue }