Jelajahi Sumber

Clippy issues

Cesar Rodas 10 bulan lalu
induk
melakukan
1085574168

+ 1 - 1
crates/storage/src/event_filter.rs

@@ -134,6 +134,6 @@ impl EventFilter {
             }
         }
 
-        return true;
+        true
     }
 }

+ 3 - 3
crates/storage/src/notification.rs

@@ -74,11 +74,11 @@ where
 
     /// Subscribes to a filter. The first streamed bytes will be reads from the
     /// database.
-    pub fn subscribe<'a>(
-        &'a self,
+    pub fn subscribe(
+        &self,
         filter: Filter,
         sender: Sender<(usize, Event)>,
-    ) -> Result<(usize, SubscriptionResultFromDb<T::Iterator<'a>>), Error> {
+    ) -> Result<(usize, SubscriptionResultFromDb<T::Iterator<'_>>), Error> {
         let mut subscribers = self.subscriptions.write();
         let mut _subscription_listener = self.subscription_listener.write();
         let id = self

+ 8 - 8
crates/storage/src/rocksdb/mod.rs

@@ -87,7 +87,7 @@ impl RocksDb {
 
 impl Storage for RocksDb {
     type Iterator<'a> = WrapperIterator<'a>;
-    fn get_local_events<'a>(&'a self, limit: Option<usize>) -> Result<WrapperIterator<'a>, Error> {
+    fn get_local_events(&self, limit: Option<usize>) -> Result<WrapperIterator<'_>, Error> {
         let cf_handle = self.reference_to_cf_handle(ReferenceType::LocalEvents)?;
         Ok(WrapperIterator {
             db: self,
@@ -106,8 +106,8 @@ impl Storage for RocksDb {
         let secondary_index = SecondaryIndex::new(event_id, event.created_at());
         self.db.put_cf(
             &self.reference_to_cf_handle(ReferenceType::LocalEvents)?,
-            secondary_index.index_by(&[]),
-            &event_id.deref(),
+            secondary_index.index_by([]),
+            event_id.deref(),
         )?;
         Ok(())
     }
@@ -125,7 +125,7 @@ impl Storage for RocksDb {
         let author_id = secondary_index.index_by(event.author());
         let json = serde_json::to_vec(event)?;
         let kind: u32 = event.kind().into();
-        let kind_id = secondary_index.index_by(&kind.to_be_bytes());
+        let kind_id = secondary_index.index_by(kind.to_be_bytes());
 
         let mut buffer = WriteBatch::default();
 
@@ -147,7 +147,7 @@ impl Storage for RocksDb {
 
         buffer.put_cf(
             &self.reference_to_cf_handle(ReferenceType::Stream)?,
-            secondary_index.index_by(&[]),
+            secondary_index.index_by([]),
             event_id.deref(),
         );
 
@@ -155,7 +155,7 @@ impl Storage for RocksDb {
             match tag {
                 Tag::PubKey(p) => {
                     let foreign_id = secondary_index.index_by(&p.id);
-                    let local_id = secondary_index.index_by(&event_id);
+                    let local_id = secondary_index.index_by(event_id);
 
                     buffer.put_cf(
                         &self.reference_to_cf_handle(ReferenceType::RefPublicKey)?,
@@ -170,7 +170,7 @@ impl Storage for RocksDb {
                 }
                 Tag::Event(e) => {
                     let foreign_id = secondary_index.index_by(&e.id);
-                    let local_id = secondary_index.index_by(&event_id);
+                    let local_id = secondary_index.index_by(event_id);
 
                     buffer.put_cf(
                         &self.reference_to_cf_handle(ReferenceType::RefEvent)?,
@@ -200,7 +200,7 @@ impl Storage for RocksDb {
             .transpose()?)
     }
 
-    fn get_by_filter<'a>(&'a self, mut query: Filter) -> Result<WrapperIterator<'a>, Error> {
+    fn get_by_filter(&self, mut query: Filter) -> Result<WrapperIterator<'_>, Error> {
         let limit = if query.limit == 0 {
             None
         } else {

+ 2 - 2
crates/storage/src/storage.rs

@@ -24,10 +24,10 @@ pub trait Storage {
     /// The first step is to use one available index to get a list of event-IDs,
     /// then call `load_and_filter_events` that will load the events from the
     /// `Events` namespace and will filter them by the given parameters.
-    fn get_by_filter<'a>(&'a self, query: Filter) -> Result<Self::Iterator<'a>, Error>;
+    fn get_by_filter(&self, query: Filter) -> Result<Self::Iterator<'_>, Error>;
 
     /// Return a vector of all local events
-    fn get_local_events<'a>(&'a self, limit: Option<usize>) -> Result<Self::Iterator<'a>, Error>;
+    fn get_local_events(&self, limit: Option<usize>) -> Result<Self::Iterator<'_>, Error>;
 
     /// Stores an event, similar to store(Event), but keeps track of this event in a
     /// local index. This is useful to keep track of the events that are created by

+ 1 - 10
crates/types/src/types/addr.rs

@@ -59,7 +59,7 @@ impl ToString for HumanReadablePart {
 ///
 /// Clients may want to use the Bech32 encoded address *but* the protocol only
 /// cares about hex-encoded binary data.
-#[derive(Debug, Clone, Eq)]
+#[derive(Debug, Default, Clone, Eq)]
 pub struct Addr {
     /// Bytes (up to 32 bytes)
     pub bytes: Vec<u8>,
@@ -67,15 +67,6 @@ pub struct Addr {
     pub hrp: Option<HumanReadablePart>,
 }
 
-impl Default for Addr {
-    fn default() -> Self {
-        Addr {
-            bytes: vec![],
-            hrp: None,
-        }
-    }
-}
-
 impl AsRef<[u8]> for Addr {
     fn as_ref(&self) -> &[u8] {
         &self.bytes

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

@@ -35,7 +35,7 @@ impl TryFrom<String> for Id {
     type Error = String;
     fn try_from(value: String) -> Result<Self, Self::Error> {
         Ok(Self(
-            hex::decode(&value)
+            hex::decode(value)
                 .map_err(|e| e.to_string())?
                 .try_into()
                 .map_err(|_| "Invalid length for Id".to_string())?,

+ 1 - 3
crates/types/src/types/kind.rs

@@ -52,9 +52,7 @@ pub enum Kind {
 
 impl PartialOrd for Kind {
     fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
-        let kind_id: u32 = (*self).into();
-        let other_kind_id: u32 = (*other).into();
-        kind_id.partial_cmp(&other_kind_id)
+        Some(self.cmp(other))
     }
 }
 

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

@@ -47,7 +47,7 @@ impl TryFrom<String> for Signature {
     type Error = Error;
 
     fn try_from(value: String) -> Result<Self, Self::Error> {
-        let bytes = hex::decode(&value)?;
+        let bytes = hex::decode(value)?;
         if bytes.len() != 64 {
             return Err(Error::InvalidSize);
         }