Browse Source

Fixed clippy issues

Cesar Rodas 3 months ago
parent
commit
5c262f8e93

File diff suppressed because it is too large
+ 686 - 16
Cargo.lock


+ 1 - 1
Cargo.toml

@@ -4,7 +4,7 @@ version = "0.1.0"
 edition = "2021"
 
 [workspace]
-members = ["crates/types", "crates/client", "crates/relayer", "crates/storage/base", "crates/storage/rocksdb"]
+members = ["crates/types", "crates/client", "crates/relayer", "crates/storage/base", "crates/storage/rocksdb", "crates/storage/sqlx"]
 
 [dependencies]
 nostr-rs-types = { path = "crates/types" }

+ 16 - 8
crates/types/src/types/addr.rs

@@ -9,7 +9,11 @@ use serde::{
     de::{self, Deserialize, Deserializer},
     ser::{self, Serializer},
 };
-use std::{hash::Hash, ops::Deref};
+use std::{
+    fmt::{self, Display},
+    hash::Hash,
+    ops::Deref,
+};
 use thiserror::Error;
 
 /// Errors
@@ -45,13 +49,17 @@ pub enum HumanReadablePart {
     Note,
 }
 
-impl ToString for HumanReadablePart {
-    fn to_string(&self) -> String {
-        match *self {
-            Self::NPub => "npub".to_owned(),
-            Self::NSec => "nsec".to_owned(),
-            Self::Note => "note".to_owned(),
-        }
+impl Display for HumanReadablePart {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(
+            f,
+            "{}",
+            match self {
+                Self::NPub => "npub",
+                Self::NSec => "nsec",
+                Self::Note => "note",
+            }
+        )
     }
 }
 

+ 3 - 0
crates/types/src/types/filter.rs

@@ -10,6 +10,9 @@ use serde::{Deserialize, Serialize};
 use super::Kind;
 
 /// Filter
+///
+/// As defined in Nostr, all this filters options are AND, meaning that an object must match all the
+/// requirements in order to be included in the resultset
 #[derive(Serialize, Deserialize, Default, Debug, Clone)]
 pub struct Filter {
     /// Fetch events by their Id, or subscribe

+ 7 - 4
crates/types/src/types/id.rs

@@ -4,7 +4,10 @@ use serde::{
     ser::{self, Serializer},
     Deserialize,
 };
-use std::ops::Deref;
+use std::{
+    fmt::{self, Display},
+    ops::Deref,
+};
 
 /// Event Id
 ///
@@ -25,9 +28,9 @@ impl Deref for Id {
     }
 }
 
-impl ToString for Id {
-    fn to_string(&self) -> String {
-        hex::encode(self.0)
+impl Display for Id {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "{}", hex::encode(self.0))
     }
 }
 

+ 7 - 4
crates/types/src/types/signature.rs

@@ -3,7 +3,10 @@ use serde::{
     de::{self, Deserialize, Deserializer},
     ser::{self, Serializer},
 };
-use std::ops::Deref;
+use std::{
+    fmt::{self, Display},
+    ops::Deref,
+};
 use thiserror::Error;
 
 /// Errors
@@ -37,9 +40,9 @@ impl Deref for Signature {
     }
 }
 
-impl ToString for Signature {
-    fn to_string(&self) -> String {
-        hex::encode(self.0)
+impl Display for Signature {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", hex::encode(self.0))
     }
 }
 

+ 8 - 4
crates/types/src/types/subscription_id.rs

@@ -3,7 +3,11 @@
 //! This mod abstract the subscription and makes sure it is valid
 use hex::ToHex;
 use rand::RngCore;
-use std::{convert::TryFrom, ops::Deref};
+use std::{
+    convert::TryFrom,
+    fmt::{self, Display},
+    ops::Deref,
+};
 use thiserror::Error;
 
 /// Error type
@@ -55,9 +59,9 @@ impl Default for SubscriptionId {
     }
 }
 
-impl ToString for SubscriptionId {
-    fn to_string(&self) -> String {
-        self.0.clone()
+impl Display for SubscriptionId {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", self.0)
     }
 }
 

+ 13 - 9
crates/types/src/types/tag/event.rs

@@ -1,5 +1,6 @@
 //! Event tag
 use super::Addr;
+use std::fmt::{self, Display};
 
 /// A tag that references another event
 #[derive(Debug, PartialEq, Eq, Clone)]
@@ -26,15 +27,18 @@ pub enum Marker {
     Unknown(String),
 }
 
-impl ToString for Marker {
-    fn to_string(&self) -> String {
-        (match self {
-            Self::Root => "root",
-            Self::Reply => "reply",
-            Self::Mention => "mention",
-            Self::Unknown(x) => x,
-        })
-        .to_owned()
+impl Display for Marker {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(
+            f,
+            "{}",
+            match self {
+                Self::Root => "root",
+                Self::Reply => "reply",
+                Self::Mention => "mention",
+                Self::Unknown(x) => x,
+            }
+        )
     }
 }
 

Some files were not shown because too many files changed in this diff