commit 8ad9ad20ba6f20f97d43d3abc99dc4cffce4ca5b
parent 8a8779159401ef2270634c53b690b9f4a0ec72df
Author: William Casarin <jb55@jb55.com>
Date: Sat, 25 Jan 2025 16:15:06 -0800
Merge clippy fixes from Dimitris
Dimitris Apostolou (1):
Fix clippy warnings
Diffstat:
4 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/crates/enostr/src/relay/message.rs b/crates/enostr/src/relay/message.rs
@@ -9,9 +9,7 @@ pub struct CommandResult<'a> {
}
pub fn calculate_command_result_size(result: &CommandResult) -> usize {
- std::mem::size_of_val(result)
- + result.event_id.as_bytes().len()
- + result.message.as_bytes().len()
+ std::mem::size_of_val(result) + result.event_id.len() + result.message.len()
}
#[derive(Debug, Eq, PartialEq)]
diff --git a/crates/enostr/src/relay/subs_debug.rs b/crates/enostr/src/relay/subs_debug.rs
@@ -188,13 +188,13 @@ fn calculate_client_message_size(message: &ClientMessage) -> usize {
ClientMessage::Req { sub_id, filters } => {
mem::size_of_val(message)
+ mem::size_of_val(sub_id)
- + sub_id.as_bytes().len()
+ + sub_id.len()
+ filters.iter().map(mem::size_of_val).sum::<usize>()
}
ClientMessage::Close { sub_id } => {
- mem::size_of_val(message) + mem::size_of_val(sub_id) + sub_id.as_bytes().len()
+ mem::size_of_val(message) + mem::size_of_val(sub_id) + sub_id.len()
}
- ClientMessage::Raw(data) => mem::size_of_val(message) + data.as_bytes().len(),
+ ClientMessage::Raw(data) => mem::size_of_val(message) + data.len(),
}
}
@@ -217,7 +217,7 @@ fn calculate_ws_message_size(message: &WsMessage) -> usize {
mem::size_of_val(message) + vec.len()
}
WsMessage::Text(string) | WsMessage::Unknown(string) => {
- mem::size_of_val(message) + string.as_bytes().len()
+ mem::size_of_val(message) + string.len()
}
}
}
@@ -233,13 +233,11 @@ fn calculate_error_size(error: &Error) -> usize {
| Error::Io(_)
| Error::InvalidPublicKey => mem::size_of_val(error), // No heap usage
- Error::Json(json_err) => mem::size_of_val(error) + json_err.to_string().as_bytes().len(),
+ Error::Json(json_err) => mem::size_of_val(error) + json_err.to_string().len(),
- Error::Nostrdb(nostrdb_err) => {
- mem::size_of_val(error) + nostrdb_err.to_string().as_bytes().len()
- }
+ Error::Nostrdb(nostrdb_err) => mem::size_of_val(error) + nostrdb_err.to_string().len(),
- Error::Generic(string) => mem::size_of_val(error) + string.as_bytes().len(),
+ Error::Generic(string) => mem::size_of_val(error) + string.len(),
}
}
@@ -248,7 +246,7 @@ fn calculate_relay_message_size(message: &RelayMessage) -> usize {
RelayMessage::OK(result) => calculate_command_result_size(result),
RelayMessage::Eose(str_ref)
| RelayMessage::Event(str_ref, _)
- | RelayMessage::Notice(str_ref) => mem::size_of_val(message) + str_ref.as_bytes().len(),
+ | RelayMessage::Notice(str_ref) => mem::size_of_val(message) + str_ref.len(),
}
}
diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs
@@ -118,10 +118,10 @@ impl AccountRelayData {
if let Some(url) = tag.get(1).and_then(|f| f.variant().str()) {
let has_read_marker = tag
.get(2)
- .map_or(false, |m| m.variant().str() == Some("read"));
+ .is_some_and(|m| m.variant().str() == Some("read"));
let has_write_marker = tag
.get(2)
- .map_or(false, |m| m.variant().str() == Some("write"));
+ .is_some_and(|m| m.variant().str() == Some("write"));
relays.push(RelaySpec::new(
Self::canonicalize_url(url),
has_read_marker,
diff --git a/crates/notedeck_columns/src/ui/column/header.rs b/crates/notedeck_columns/src/ui/column/header.rs
@@ -96,7 +96,7 @@ impl<'a> NavTitle<'a> {
)))
}
}
- } else if back_button_resp.map_or(false, |r| r.clicked()) {
+ } else if back_button_resp.is_some_and(|r| r.clicked()) {
Some(RenderNavAction::Back)
} else {
None
@@ -427,7 +427,7 @@ impl<'a> NavTitle<'a> {
let is_hashtag = self
.columns
.find_timeline(*tlid)
- .map_or(false, |tl| matches!(tl.kind, TimelineKind::Hashtag(_)));
+ .is_some_and(|tl| matches!(tl.kind, TimelineKind::Hashtag(_)));
if is_hashtag {
ui.add(