notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 1f149aec3b22d1485d6152bcc88bd861269c027b
parent 973a7c780f2747439b2378992513c8cca51b9ca5
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 19 Aug 2024 21:19:39 -0700

fix clippy warnings

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Menostr/src/client/message.rs | 2+-
Menostr/src/error.rs | 1-
Menostr/src/keypair.rs | 22++++++----------------
Menostr/src/note.rs | 2+-
Menostr/src/relay/message.rs | 10+++++-----
Menostr/src/relay/pool.rs | 24++++++++++++++----------
Msrc/ui/mention.rs | 2+-
7 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/enostr/src/client/message.rs b/enostr/src/client/message.rs @@ -47,7 +47,7 @@ impl ClientMessage { format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str) } else { let filters_json_str: Result<Vec<String>, Error> = filters - .into_iter() + .iter() .map(|f| f.json().map_err(Into::<Error>::into)) .collect(); format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str?.join(",")) diff --git a/enostr/src/error.rs b/enostr/src/error.rs @@ -1,5 +1,4 @@ //use nostr::prelude::secp256k1; -use serde_json; use std::array::TryFromSliceError; use std::fmt; diff --git a/enostr/src/keypair.rs b/enostr/src/keypair.rs @@ -62,7 +62,7 @@ impl FullKeypair { let secret_key = nostr::SecretKey::from(*secret_key); FullKeypair { pubkey: Pubkey::new(&xopk.serialize()), - secret_key: SecretKey::from(secret_key), + secret_key, } } @@ -90,11 +90,7 @@ impl std::fmt::Display for Keypair { impl std::fmt::Display for FullKeypair { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Keypair:\n\tpublic: {}\n\tsecret: {}", - self.pubkey, "<hidden>" - ) + write!(f, "Keypair:\n\tpublic: {}\n\tsecret: <hidden>", self.pubkey) } } @@ -108,14 +104,9 @@ impl SerializableKeypair { pub fn from_keypair(kp: &Keypair, pass: &str, log_n: u8) -> Self { Self { pubkey: kp.pubkey.clone(), - encrypted_secret_key: kp - .secret_key - .clone() - .map(|s| { - EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak) - .ok() - }) - .flatten(), + encrypted_secret_key: kp.secret_key.clone().and_then(|s| { + EncryptedSecretKey::new(&s, pass, log_n, nostr::nips::nip49::KeySecurity::Weak).ok() + }), } } @@ -123,8 +114,7 @@ impl SerializableKeypair { Keypair::new( self.pubkey.clone(), self.encrypted_secret_key - .map(|e| e.to_secret_key(pass).ok()) - .flatten(), + .and_then(|e| e.to_secret_key(pass).ok()), ) } } diff --git a/enostr/src/note.rs b/enostr/src/note.rs @@ -66,7 +66,7 @@ impl Note { } pub fn verify(&self) -> Result<Self, Error> { - return Err(Error::InvalidSignature); + Err(Error::InvalidSignature) } /// This is just for serde sanity checking diff --git a/enostr/src/relay/message.rs b/enostr/src/relay/message.rs @@ -39,7 +39,7 @@ impl<'a> From<&'a WsEvent> for RelayEvent<'a> { impl<'a> From<&'a WsMessage> for RelayEvent<'a> { fn from(wsmsg: &'a WsMessage) -> RelayEvent<'a> { match wsmsg { - WsMessage::Text(ref s) => match RelayMessage::from_json(&s).map(RelayEvent::Message) { + WsMessage::Text(s) => match RelayMessage::from_json(s).map(RelayEvent::Message) { Ok(msg) => msg, Err(err) => RelayEvent::Error(err), }, @@ -59,9 +59,9 @@ impl<'a> RelayMessage<'a> { pub fn ok(event_id: &'a str, status: bool, message: &'a str) -> Self { RelayMessage::OK(CommandResult { - event_id: event_id, + event_id, status, - message: message, + message, }) } @@ -78,7 +78,7 @@ impl<'a> RelayMessage<'a> { // Relay response format: ["NOTICE", <message>] if &msg[0..=9] == "[\"NOTICE\"," { // TODO: there could be more than one space, whatever - let start = if msg.bytes().nth(10) == Some(b' ') { + let start = if msg.as_bytes().get(10).copied() == Some(b' ') { 12 } else { 11 @@ -96,7 +96,7 @@ impl<'a> RelayMessage<'a> { // EOSE (NIP-15) // Relay response format: ["EOSE", <subscription_id>] if &msg[0..=7] == "[\"EOSE\"," { - let start = if msg.bytes().nth(8) == Some(b' ') { + let start = if msg.as_bytes().get(8).copied() == Some(b' ') { 10 } else { 9 diff --git a/enostr/src/relay/pool.rs b/enostr/src/relay/pool.rs @@ -26,7 +26,7 @@ pub struct PoolRelay { impl PoolRelay { pub fn new(relay: Relay) -> PoolRelay { PoolRelay { - relay: relay, + relay, last_ping: Instant::now(), last_connect_attempt: Instant::now(), retry_connect_after: Self::initial_reconnect_duration(), @@ -43,6 +43,12 @@ pub struct RelayPool { pub ping_rate: Duration, } +impl Default for RelayPool { + fn default() -> Self { + RelayPool::new() + } +} + impl RelayPool { // Constructs a new, empty RelayPool. pub fn new() -> RelayPool { @@ -59,11 +65,12 @@ impl RelayPool { pub fn has(&self, url: &str) -> bool { for relay in &self.relays { - if &relay.relay.url == url { + if relay.relay.url == url { return true; } } - return false; + + false } pub fn send(&mut self, cmd: &ClientMessage) { @@ -157,7 +164,7 @@ impl RelayPool { /// function searches each relay in the list in order, attempting to /// receive a message from each. If a message is received, return it. /// If no message is received from any relays, None is returned. - pub fn try_recv<'a>(&'a mut self) -> Option<PoolEvent<'a>> { + pub fn try_recv(&mut self) -> Option<PoolEvent<'_>> { for relay in &mut self.relays { let relay = &mut relay.relay; if let Some(event) = relay.receiver.try_recv() { @@ -176,12 +183,9 @@ impl RelayPool { // let's just handle pongs here. // We only need to do this natively. #[cfg(not(target_arch = "wasm32"))] - match &ev { - WsMessage::Ping(ref bs) => { - debug!("pong {}", &relay.url); - relay.sender.send(WsMessage::Pong(bs.to_owned())); - } - _ => {} + if let WsMessage::Ping(ref bs) = ev { + debug!("pong {}", &relay.url); + relay.sender.send(WsMessage::Pong(bs.to_owned())); } } } diff --git a/src/ui/mention.rs b/src/ui/mention.rs @@ -45,7 +45,7 @@ fn mention_ui( pk: &[u8; 32], ui: &mut egui::Ui, size: f32, - selectable: bool + selectable: bool, ) -> egui::Response { #[cfg(feature = "profiling")] puffin::profile_function!();