From 0b2763ab8b1b5d7c852718826ded9ec801dfc96c Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 25 Apr 2020 20:49:29 -0500 Subject: [PATCH] Clippy --- src/apub.rs | 2 +- src/data/actor.rs | 8 ++++---- src/data/media.rs | 5 ++--- src/data/node.rs | 8 ++++---- src/data/state.rs | 5 ++--- src/db.rs | 4 ++-- src/jobs/apub/reject.rs | 2 +- src/jobs/apub/undo.rs | 2 +- src/jobs/nodeinfo.rs | 4 ++-- src/middleware/webfinger.rs | 4 +++- src/notify.rs | 2 +- src/routes/actor.rs | 2 +- src/routes/inbox.rs | 7 +++---- 13 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/apub.rs b/src/apub.rs index 0f019c6..deafc07 100644 --- a/src/apub.rs +++ b/src/apub.rs @@ -93,7 +93,7 @@ pub struct Endpoints { } impl PublicKey { - pub fn to_ext(self) -> PublicKeyExtension { + pub fn into_ext(self) -> PublicKeyExtension { self.into() } } diff --git a/src/data/actor.rs b/src/data/actor.rs index b827c07..a0ac989 100644 --- a/src/data/actor.rs +++ b/src/data/actor.rs @@ -65,15 +65,15 @@ impl ActorCache { let inbox_host = accepted_actor.inbox().as_url().host(); if input_host != actor_host { - let input_host = input_host.map(|h| h.to_string()).unwrap_or(String::new()); - let actor_host = actor_host.map(|h| h.to_string()).unwrap_or(String::new()); + let input_host = input_host.map(|h| h.to_string()).unwrap_or_default(); + let actor_host = actor_host.map(|h| h.to_string()).unwrap_or_default(); return Err(MyError::HostMismatch(input_host, actor_host)); } if actor_host != inbox_host { - let actor_host = actor_host.map(|h| h.to_string()).unwrap_or(String::new()); - let inbox_host = inbox_host.map(|h| h.to_string()).unwrap_or(String::new()); + let actor_host = actor_host.map(|h| h.to_string()).unwrap_or_default(); + let inbox_host = inbox_host.map(|h| h.to_string()).unwrap_or_default(); return Err(MyError::HostMismatch(actor_host, inbox_host)); } diff --git a/src/data/media.rs b/src/data/media.rs index 6b9f426..69166f4 100644 --- a/src/data/media.rs +++ b/src/data/media.rs @@ -90,9 +90,8 @@ impl Media { } pub async fn get_url(&self, uuid: Uuid) -> Result, MyError> { - match self.url_cache.lock().await.get(&uuid).cloned() { - Some(url) => return Ok(Some(url)), - _ => (), + if let Some(url) = self.url_cache.lock().await.get(&uuid).cloned() { + return Ok(Some(url)); } let row_opt = self diff --git a/src/data/node.rs b/src/data/node.rs index cfae9bd..566a863 100644 --- a/src/data/node.rs +++ b/src/data/node.rs @@ -179,7 +179,7 @@ impl NodeCache { let mut write_guard = self.nodes.write().await; let node = write_guard .entry(listener.clone()) - .or_insert(Node::new(listener)); + .or_insert_with(|| Node::new(listener)); if let Some(info) = info { node.info = Some(info.0); @@ -212,7 +212,7 @@ impl NodeCache { let mut write_guard = self.nodes.write().await; let node = write_guard .entry(listener.clone()) - .or_insert(Node::new(listener.clone())); + .or_insert_with(|| Node::new(listener.clone())); node.set_info(software, version, reg); node.clone() }; @@ -239,7 +239,7 @@ impl NodeCache { let mut write_guard = self.nodes.write().await; let node = write_guard .entry(listener.clone()) - .or_insert(Node::new(listener.clone())); + .or_insert_with(|| Node::new(listener.clone())); node.set_instance(title, description, version, reg, requires_approval); node.clone() }; @@ -265,7 +265,7 @@ impl NodeCache { let mut write_guard = self.nodes.write().await; let node = write_guard .entry(listener.clone()) - .or_insert(Node::new(listener.clone())); + .or_insert_with(|| Node::new(listener.clone())); node.set_contact(username, display_name, url, avatar); node.clone() }; diff --git a/src/data/state.rs b/src/data/state.rs index a1cd20d..afbaa96 100644 --- a/src/data/state.rs +++ b/src/data/state.rs @@ -206,9 +206,8 @@ impl State { loop { interval.tick().await; - match state.rehydrate(&db).await { - Err(e) => error!("Error rehydrating, {}", e), - _ => (), + if let Err(e) = state.rehydrate(&db).await { + error!("Error rehydrating, {}", e); } } }); diff --git a/src/db.rs b/src/db.rs index 17c6c1d..046e69a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -68,7 +68,7 @@ impl Db { for domain in domains { match add_block(&conn, domain.as_str()).await { Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => { - Err(e)?; + return Err(e.into()); } _ => (), }; @@ -89,7 +89,7 @@ impl Db { for domain in domains { match add_whitelist(&conn, domain.as_str()).await { Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => { - Err(e)?; + return Err(e.into()); } _ => (), }; diff --git a/src/jobs/apub/reject.rs b/src/jobs/apub/reject.rs index 758669e..977164e 100644 --- a/src/jobs/apub/reject.rs +++ b/src/jobs/apub/reject.rs @@ -12,7 +12,7 @@ pub struct Reject(pub Actor); impl Reject { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { - if let Some(_) = state.actors.unfollower(&self.0).await? { + if state.actors.unfollower(&self.0).await?.is_some() { state.db.remove_listener(self.0.inbox.clone()).await?; } diff --git a/src/jobs/apub/undo.rs b/src/jobs/apub/undo.rs index 0a7ab4c..d013c63 100644 --- a/src/jobs/apub/undo.rs +++ b/src/jobs/apub/undo.rs @@ -22,7 +22,7 @@ impl Undo { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { let was_following = state.actors.is_following(&self.actor.id).await; - if let Some(_) = state.actors.unfollower(&self.actor).await? { + if state.actors.unfollower(&self.actor).await?.is_some() { state.db.remove_listener(self.actor.inbox.clone()).await?; } diff --git a/src/jobs/nodeinfo.rs b/src/jobs/nodeinfo.rs index a8366d6..c833771 100644 --- a/src/jobs/nodeinfo.rs +++ b/src/jobs/nodeinfo.rs @@ -110,8 +110,8 @@ impl MaybeSupported { struct SupportedVersion(String); struct SupportedNodeinfo(String); -static SUPPORTED_VERSIONS: &'static str = "2."; -static SUPPORTED_NODEINFO: &'static str = "http://nodeinfo.diaspora.software/ns/schema/2."; +static SUPPORTED_VERSIONS: &str = "2."; +static SUPPORTED_NODEINFO: &str = "http://nodeinfo.diaspora.software/ns/schema/2."; struct SupportedVersionVisitor; struct SupportedNodeinfoVisitor; diff --git a/src/middleware/webfinger.rs b/src/middleware/webfinger.rs index f0098f7..622394e 100644 --- a/src/middleware/webfinger.rs +++ b/src/middleware/webfinger.rs @@ -13,6 +13,8 @@ pub struct RelayResolver; #[error("Error resolving webfinger data")] pub struct RelayError; +type FutResult = dyn Future>; + impl Resolver for RelayResolver { type State = (Data, Data); type Error = RelayError; @@ -21,7 +23,7 @@ impl Resolver for RelayResolver { account: &str, domain: &str, (state, config): Self::State, - ) -> Pin, Self::Error>>>> { + ) -> Pin, Self::Error>>> { let domain = domain.to_owned(); let account = account.to_owned(); diff --git a/src/notify.rs b/src/notify.rs index e18356f..51e83ae 100644 --- a/src/notify.rs +++ b/src/notify.rs @@ -37,7 +37,7 @@ impl Notifier { let v = self .listeners .entry(l.key().to_owned()) - .or_insert(Vec::new()); + .or_insert_with(Vec::new); v.push(Box::new(l)); self } diff --git a/src/routes/actor.rs b/src/routes/actor.rs index dd92458..018fdb9 100644 --- a/src/routes/actor.rs +++ b/src/routes/actor.rs @@ -44,5 +44,5 @@ pub async fn route( public_key_pem: state.public_key.to_pem_pkcs8()?, }; - Ok(ok(application.extend(public_key.to_ext()))) + Ok(ok(application.extend(public_key.into_ext()))) } diff --git a/src/routes/inbox.rs b/src/routes/inbox.rs index 33796bd..b39b33a 100644 --- a/src/routes/inbox.rs +++ b/src/routes/inbox.rs @@ -21,8 +21,7 @@ pub async fn route( client: web::Data, jobs: web::Data, input: web::Json, - verified: Option, - digest_verified: Option, + verified: Option<(SignatureVerified, DigestVerified)>, ) -> Result { let input = input.into_inner(); @@ -46,10 +45,10 @@ pub async fn route( return Err(MyError::NotSubscribed(actor.inbox.to_string())); } - if config.validate_signatures() && (digest_verified.is_none() || verified.is_none()) { + if config.validate_signatures() && verified.is_none() { return Err(MyError::NoSignature(actor.public_key_id.to_string())); } else if config.validate_signatures() { - if let Some(verified) = verified { + if let Some((verified, _)) = verified { if actor.public_key_id.as_str() != verified.key_id() { error!("Bad actor, more info: {:?}", input); return Err(MyError::BadActor(