Przeglądaj źródła

Fixed clippy issues

Cesar Rodas 2 miesięcy temu
rodzic
commit
04c7a5830f

+ 3 - 3
crates/relayer/src/relayer.rs

@@ -220,7 +220,7 @@ impl<T: Storage + Send + Sync + 'static> Relayer<T> {
     ///
     /// This function could change in the future tu kick connections programmatically
     pub fn drop_connection(self: &Arc<Self>, local_connection: &LocalConnection<T>) {
-        let id = local_connection.conn_id.clone();
+        let id = local_connection.conn_id;
         let this = self.clone();
 
         tokio::spawn(async move {
@@ -860,7 +860,7 @@ mod test {
 
         assert_eq!(relayer.total_subscribers(), 1100);
 
-        publisher.send(get_note().into()).await.expect("valid send");
+        publisher.send(get_note()).await.expect("valid send");
 
         sleep(Duration::from_millis(10)).await;
 
@@ -955,7 +955,7 @@ mod test {
         assert!(local_connection_1.try_recv().is_none());
 
         local_connection_0
-            .send(get_note().into())
+            .send(get_note())
             .await
             .expect("valid send");
 

+ 2 - 3
crates/subscription-manager/src/filter.rs

@@ -33,7 +33,6 @@ impl From<FilterT> for SortedFilter {
         let tags = query
             .tags
             .into_iter()
-            .map(|(tag, values)| (tag, values))
             .collect::<HashMap<String, HashSet<TagValue>>>();
 
         let kinds = query.kinds.into_iter().collect::<HashSet<Kind>>();
@@ -99,8 +98,8 @@ impl SortedFilter {
                     tag.get_indexable_value()
                         .map(|f| (tag.get_identifier().to_owned(), f))
                 })
-                .fold(HashMap::new(), |mut acc, (key, value)| {
-                    acc.entry(key).or_insert_with(HashSet::new).insert(value);
+                .fold(HashMap::<_, HashSet<_>>::new(), |mut acc, (key, value)| {
+                    acc.entry(key).or_default().insert(value);
                     acc
                 });
 

+ 3 - 2
crates/subscription-manager/src/index.rs

@@ -32,8 +32,9 @@ impl Index {
         subscriptions.push(Index::Id(event.id.to_owned()));
 
         for t in event.tags() {
-            t.get_indexable_value()
-                .map(|v| subscriptions.push(Index::Tag(t.get_identifier().to_owned(), v)));
+            if let Some(v) = t.get_indexable_value() {
+                subscriptions.push(Index::Tag(t.get_identifier().to_owned(), v));
+            }
         }
 
         subscriptions.push(Index::Kind(event.kind()));

+ 2 - 3
crates/subscription-manager/src/lib.rs

@@ -147,14 +147,13 @@ where
 
         for idx in event_index {
             let start_index = (idx.clone(), I::default());
-            let mut start = indexes.range(&start_index..);
 
-            while let Some(((current_idx, subscription_id), filter)) = start.next() {
+            for ((current_idx, subscription_id), filter) in indexes.range(&start_index..) {
                 if current_idx != &idx {
                     break;
                 }
 
-                if !matched.contains(subscription_id) && filter.check_event(&event) {
+                if !matched.contains(subscription_id) && filter.check_event(event) {
                     matched.insert(subscription_id.clone());
                 }
             }

+ 5 - 5
crates/types/src/lib.rs

@@ -13,6 +13,11 @@ pub mod types;
 
 pub use self::{request::Request, response::Response};
 
+#[macro_use]
+extern crate custom_derive;
+#[macro_use]
+extern crate enum_derive;
+
 #[cfg(test)]
 mod regression {
     use crate::types::Event;
@@ -27,8 +32,3 @@ mod regression {
             });
     }
 }
-
-#[macro_use]
-extern crate custom_derive;
-#[macro_use]
-extern crate enum_derive;

+ 1 - 0
crates/types/src/relayer/ok.rs

@@ -55,6 +55,7 @@ impl ROkStatus {
     }
 
     /// Human readable status
+    #[allow(clippy::inherent_to_string)]
     pub fn to_string(&self) -> String {
         let message = match self {
             ROkStatus::Ok => "",

+ 3 - 2
crates/types/src/response.rs

@@ -236,8 +236,9 @@ mod test {
         jsons
             .iter()
             .map(|json| {
-                let message: Response =
-                    serde_json::from_str(json).expect(&format!("valid message: {}", json));
+                let message: Response = serde_json::from_str(json)
+                    .unwrap_or_else(|_| panic!("valid message: {}", json));
+
                 assert!(message.as_event().is_some());
             })
             .for_each(drop);

+ 2 - 2
crates/types/src/types/filter.rs

@@ -63,8 +63,8 @@ where
         {
             let mut tags = HashMap::new();
             while let Some((key, value)) = map.next_entry::<String, _>()? {
-                if key.starts_with('#') {
-                    tags.insert(key[1..].to_string(), value);
+                if let Some(stripped) = key.strip_prefix('#') {
+                    tags.insert(stripped.to_string(), value);
                 }
             }
             Ok(tags)

+ 1 - 1
crates/types/src/types/id.rs

@@ -27,7 +27,7 @@ impl TryFrom<&str> for Id {
         if hex::decode_to_slice(value, &mut slice).is_ok() {
             return Ok(Id(slice));
         }
-        let (hrp, bytes, _) = bech32::decode(&value)?;
+        let (hrp, bytes, _) = bech32::decode(value)?;
         match hrp.to_lowercase().as_str() {
             "npub" | "nsec" | "note" => {}
             _ => return Err(Error::UnexpectedHrp),

+ 5 - 8
crates/types/src/types/tag.rs

@@ -143,7 +143,7 @@ impl Tag {
             Tag::Hashtag(content) | Tag::Title(content) => Some(TagValue::String(content.clone())),
             Tag::Relay((_, url), _) => Some(TagValue::String(url.to_string())),
             Tag::Unknown(_, args) => {
-                let value = args.get(0).cloned().unwrap_or_default();
+                let value = args.first().cloned().unwrap_or_default();
                 Some(
                     value
                         .as_str()
@@ -254,10 +254,7 @@ impl<'de> Deserialize<'de> for Tag {
             0 => return Ok(Tag::Empty),
             1 => {
                 let tag_name = parts.pop_front().unwrap_or_default();
-                match tag_name.as_str() {
-                    "encrypted" => return Ok(Tag::Encrypted),
-                    _ => {}
-                }
+                if tag_name.as_str() == "encrypted" { return Ok(Tag::Encrypted) }
                 return Ok(Tag::Unknown(tag_name, vec![]));
             }
             _ => {}
@@ -271,16 +268,16 @@ impl<'de> Deserialize<'de> for Tag {
                 .pop_front()
                 .ok_or_else::<D::Error, _>(|| de::Error::custom("missing argument"))
                 .and_then(|id| id.parse().map_err(de::Error::custom))
-                .and_then(|id| {
+                .map(|id| {
                     let relayer_url = parts.pop_front().map(|value| (value.parse().ok(), value));
 
                     let extra = parts.pop_front();
-                    Ok(match tag_type.as_str() {
+                    match tag_type.as_str() {
                         "e" => Tag::Event(id, relayer_url, extra.map(|x| x.as_str().into())),
                         "goal" => Tag::ZapGoal(id, relayer_url),
                         "p" => Tag::PubKey(id, relayer_url, extra),
                         _ => unreachable!(),
-                    })
+                    }
                 }),
             "expiration" => {
                 let timestamp = parts