clippy fixes

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-07-17 13:49:53 -07:00
parent a4c1b38116
commit 8a1398face
26 changed files with 51 additions and 62 deletions

View File

@@ -56,10 +56,10 @@ impl ClientMessage {
Self::Raw(raw) => raw.clone(), Self::Raw(raw) => raw.clone(),
Self::Req { sub_id, filters } => { Self::Req { sub_id, filters } => {
if filters.is_empty() { if filters.is_empty() {
format!("[\"REQ\",\"{}\",{{ }}]", sub_id) format!("[\"REQ\",\"{sub_id}\",{{ }}]")
} else if filters.len() == 1 { } else if filters.len() == 1 {
let filters_json_str = filters[0].json()?; let filters_json_str = filters[0].json()?;
format!("[\"REQ\",\"{}\",{}]", sub_id, filters_json_str) format!("[\"REQ\",\"{sub_id}\",{filters_json_str}]")
} else { } else {
let filters_json_str: Result<Vec<String>, Error> = filters let filters_json_str: Result<Vec<String>, Error> = filters
.iter() .iter()

View File

@@ -46,8 +46,8 @@ impl From<RelayEvent<'_>> for OwnedRelayEvent {
RelayEvent::Other(ws_message) => { RelayEvent::Other(ws_message) => {
let ws_str = match ws_message { let ws_str = match ws_message {
WsMessage::Binary(_) => "Binary".to_owned(), WsMessage::Binary(_) => "Binary".to_owned(),
WsMessage::Text(t) => format!("Text:{}", t), WsMessage::Text(t) => format!("Text:{t}"),
WsMessage::Unknown(u) => format!("Unknown:{}", u), WsMessage::Unknown(u) => format!("Unknown:{u}"),
WsMessage::Ping(_) => "Ping".to_owned(), WsMessage::Ping(_) => "Ping".to_owned(),
WsMessage::Pong(_) => "Pong".to_owned(), WsMessage::Pong(_) => "Pong".to_owned(),
}; };
@@ -57,9 +57,9 @@ impl From<RelayEvent<'_>> for OwnedRelayEvent {
RelayEvent::Message(relay_message) => { RelayEvent::Message(relay_message) => {
let relay_msg = match relay_message { let relay_msg = match relay_message {
RelayMessage::OK(_) => "OK".to_owned(), RelayMessage::OK(_) => "OK".to_owned(),
RelayMessage::Eose(s) => format!("EOSE:{}", s), RelayMessage::Eose(s) => format!("EOSE:{s}"),
RelayMessage::Event(_, s) => format!("EVENT:{}", s), RelayMessage::Event(_, s) => format!("EVENT:{s}"),
RelayMessage::Notice(s) => format!("NOTICE:{}", s), RelayMessage::Notice(s) => format!("NOTICE:{s}"),
}; };
OwnedRelayEvent::Message(relay_msg) OwnedRelayEvent::Message(relay_msg)
} }

View File

@@ -15,9 +15,9 @@ pub fn hybrid_contacts_filter(
add_pk: Option<&[u8; 32]>, add_pk: Option<&[u8; 32]>,
with_hashtags: bool, with_hashtags: bool,
) -> Result<HybridFilter, Error> { ) -> Result<HybridFilter, Error> {
let local = filter::filter_from_tags(&note, add_pk, with_hashtags)? let local = filter::filter_from_tags(note, add_pk, with_hashtags)?
.into_filter([1], filter::default_limit()); .into_filter([1], filter::default_limit());
let remote = filter::filter_from_tags(&note, add_pk, with_hashtags)? let remote = filter::filter_from_tags(note, add_pk, with_hashtags)?
.into_filter([1, 0], filter::default_remote_limit()); .into_filter([1, 0], filter::default_remote_limit());
Ok(HybridFilter::split(local, remote)) Ok(HybridFilter::split(local, remote))

View File

@@ -235,7 +235,7 @@ impl HybridFilter {
Self::Split(split) => &split.local, Self::Split(split) => &split.local,
// local as the same as remote in unsplit // local as the same as remote in unsplit
Self::Unsplit(local) => &local, Self::Unsplit(local) => local,
} }
} }

View File

@@ -163,11 +163,11 @@ const KB: usize = 1024;
fn byte_to_string(b: usize) -> String { fn byte_to_string(b: usize) -> String {
if b >= MB { if b >= MB {
let mbs = b as f32 / MB as f32; let mbs = b as f32 / MB as f32;
format!("{:.2} MB", mbs) format!("{mbs:.2} MB")
} else if b >= KB { } else if b >= KB {
let kbs = b as f32 / KB as f32; let kbs = b as f32 / KB as f32;
format!("{:.2} KB", kbs) format!("{kbs:.2} KB")
} else { } else {
format!("{} B", b) format!("{b} B")
} }
} }

View File

@@ -55,7 +55,7 @@ impl fmt::Display for RelaySpec {
// add the read and write markers if present // add the read and write markers if present
impl fmt::Debug for RelaySpec { impl fmt::Debug for RelaySpec {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\"{}\"", self)?; write!(f, "\"{self}\"")?;
if self.has_read_marker { if self.has_read_marker {
write!(f, " [r]")?; write!(f, " [r]")?;
} }

View File

@@ -107,7 +107,7 @@ impl Directory {
} else { } else {
Err(Error::Io(io::Error::new( Err(Error::Io(io::Error::new(
io::ErrorKind::NotFound, io::ErrorKind::NotFound,
format!("Requested file was not found: {}", file_name), format!("Requested file was not found: {file_name}"),
))) )))
} }
} }
@@ -142,8 +142,7 @@ impl Directory {
}) })
} else { } else {
Err(Error::Generic(format!( Err(Error::Generic(format!(
"Requested file was not found: {}", "Requested file was not found: {file_name}"
file_name
))) )))
} }
} }
@@ -197,8 +196,7 @@ pub fn delete_file(directory: &Path, file_name: String) -> Result<()> {
fs::remove_file(file_to_delete).map_err(Error::Io) fs::remove_file(file_to_delete).map_err(Error::Io)
} else { } else {
Err(Error::Generic(format!( Err(Error::Generic(format!(
"Requested file to delete was not found: {}", "Requested file to delete was not found: {file_name}"
file_name
))) )))
} }
} }

View File

@@ -18,37 +18,37 @@ pub fn time_ago_since(timestamp: u64) -> String {
let years = duration / 31_536_000; // seconds in a year let years = duration / 31_536_000; // seconds in a year
if years >= 1 { if years >= 1 {
return format!("{}{}yr", relstr, years); return format!("{relstr}{years}yr");
} }
let months = duration / 2_592_000; // seconds in a month (30.44 days) let months = duration / 2_592_000; // seconds in a month (30.44 days)
if months >= 1 { if months >= 1 {
return format!("{}{}mth", relstr, months); return format!("{relstr}{months}mth");
} }
let weeks = duration / 604_800; // seconds in a week let weeks = duration / 604_800; // seconds in a week
if weeks >= 1 { if weeks >= 1 {
return format!("{}{}wk", relstr, weeks); return format!("{relstr}{weeks}wk");
} }
let days = duration / 86_400; // seconds in a day let days = duration / 86_400; // seconds in a day
if days >= 1 { if days >= 1 {
return format!("{}{}d", relstr, days); return format!("{relstr}{days}d");
} }
let hours = duration / 3600; // seconds in an hour let hours = duration / 3600; // seconds in an hour
if hours >= 1 { if hours >= 1 {
return format!("{}{}h", relstr, hours); return format!("{relstr}{hours}h");
} }
let minutes = duration / 60; // seconds in a minute let minutes = duration / 60; // seconds in a minute
if minutes >= 1 { if minutes >= 1 {
return format!("{}{}m", relstr, minutes); return format!("{relstr}{minutes}m");
} }
let seconds = duration; let seconds = duration;
if seconds >= 3 { if seconds >= 3 {
return format!("{}{}s", relstr, seconds); return format!("{relstr}{seconds}s");
} }
"now".to_string() "now".to_string()

View File

@@ -467,15 +467,15 @@ pub enum ZappingError {
impl std::fmt::Display for ZappingError { impl std::fmt::Display for ZappingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
ZappingError::InvoiceFetchFailed(err) => write!(f, "Failed to fetch invoice: {}", err), ZappingError::InvoiceFetchFailed(err) => write!(f, "Failed to fetch invoice: {err}"),
ZappingError::InvalidAccount => write!(f, "Invalid account"), ZappingError::InvalidAccount => write!(f, "Invalid account"),
ZappingError::UnsupportedOperation => { ZappingError::UnsupportedOperation => {
write!(f, "Unsupported operation (e.g. profile zaps)") write!(f, "Unsupported operation (e.g. profile zaps)")
} }
ZappingError::InvalidZapAddress => write!(f, "Invalid zap address"), ZappingError::InvalidZapAddress => write!(f, "Invalid zap address"),
ZappingError::SenderNoWallet => write!(f, "Sender has no wallet"), ZappingError::SenderNoWallet => write!(f, "Sender has no wallet"),
ZappingError::InvalidNWCResponse(msg) => write!(f, "Invalid NWC response: {}", msg), ZappingError::InvalidNWCResponse(msg) => write!(f, "Invalid NWC response: {msg}"),
ZappingError::FutureError(msg) => write!(f, "Future error: {}", msg), ZappingError::FutureError(msg) => write!(f, "Future error: {msg}"),
} }
} }
} }

View File

@@ -106,8 +106,7 @@ async fn main() {
.collect(); .collect();
assert!( assert!(
completely_unrecognized.is_empty(), completely_unrecognized.is_empty(),
"unrecognized args: {:?}", "unrecognized args: {completely_unrecognized:?}"
completely_unrecognized
); );
chrome.add_app(NotedeckApp::Columns(columns)); chrome.add_app(NotedeckApp::Columns(columns));

View File

@@ -6,7 +6,7 @@ fn fallback() {
.ok() .ok()
.and_then(|cwd| cwd.file_name().and_then(|fname| fname.to_str())) .and_then(|cwd| cwd.file_name().and_then(|fname| fname.to_str()))
{ {
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", dirname); println!("cargo:rustc-env=GIT_COMMIT_HASH={dirname}");
} else { } else {
println!("cargo:rustc-env=GIT_COMMIT_HASH=unknown"); println!("cargo:rustc-env=GIT_COMMIT_HASH=unknown");
} }

View File

@@ -504,7 +504,7 @@ impl Damus {
pub fn gen_subid(&self, kind: &SubKind) -> String { pub fn gen_subid(&self, kind: &SubKind) -> String {
if self.options.contains(AppOptions::Debug) { if self.options.contains(AppOptions::Debug) {
format!("{:?}", kind) format!("{kind:?}")
} else { } else {
Uuid::new_v4().to_string() Uuid::new_v4().to_string()
} }

View File

@@ -55,8 +55,7 @@ fn available_characters(ui: &egui::Ui, family: egui::FontFamily) -> Vec<char> {
.fonts .fonts
.font(&egui::FontId::new(10.0, family)) // size is arbitrary for getting the characters .font(&egui::FontId::new(10.0, family)) // size is arbitrary for getting the characters
.characters() .characters()
.iter() .keys()
.map(|(chr, _v)| chr)
.filter(|chr| !chr.is_whitespace() && !chr.is_ascii_control()) .filter(|chr| !chr.is_whitespace() && !chr.is_ascii_control())
.copied() .copied()
.collect() .collect()

View File

@@ -270,7 +270,7 @@ impl Decks {
if self.decks.len() > 1 { if self.decks.len() > 1 {
self.decks.remove(index); self.decks.remove(index);
let info_prefix = format!("Removed deck at index {}", index); let info_prefix = format!("Removed deck at index {index}");
match index.cmp(&self.active_deck) { match index.cmp(&self.active_deck) {
std::cmp::Ordering::Less => { std::cmp::Ordering::Less => {
info!( info!(

View File

@@ -106,7 +106,7 @@ fn create_nip96_request(
) )
.into_bytes(); .into_bytes();
body.extend(file_contents); body.extend(file_contents);
body.extend(format!("\r\n--{}--\r\n", boundary).as_bytes()); body.extend(format!("\r\n--{boundary}--\r\n").as_bytes());
let headers = ehttp::Headers::new(&[ let headers = ehttp::Headers::new(&[
( (
@@ -246,7 +246,7 @@ impl MediaPath {
let file_name = path let file_name = path
.file_name() .file_name()
.and_then(|name| name.to_str()) .and_then(|name| name.to_str())
.unwrap_or(&format!("file.{}", ex)) .unwrap_or(&format!("file.{ex}"))
.to_owned(); .to_owned();
Ok(MediaPath { Ok(MediaPath {
@@ -256,8 +256,7 @@ impl MediaPath {
}) })
} else { } else {
Err(Error::Generic(format!( Err(Error::Generic(format!(
"{:?} does not have an extension", "{path:?} does not have an extension"
path
))) )))
} }
} }

View File

@@ -192,7 +192,7 @@ impl fmt::Display for MetadataKeyword {
.find(|(_, keyword)| keyword == self) .find(|(_, keyword)| keyword == self)
.map(|(name, _)| *name) .map(|(name, _)| *name)
{ {
write!(f, "{}", name) write!(f, "{name}")
} else { } else {
write!(f, "UnknownMetadataKeyword") write!(f, "UnknownMetadataKeyword")
} }

View File

@@ -83,8 +83,7 @@ fn get_log_str(interactor: &Directory) -> Option<String> {
fn get_prefix(file_name: &str, lines_displayed: usize, num_total_lines: usize) -> String { fn get_prefix(file_name: &str, lines_displayed: usize, num_total_lines: usize) -> String {
format!( format!(
"===\nDisplaying the last {} of {} lines in file {}\n===\n\n", "===\nDisplaying the last {lines_displayed} of {num_total_lines} lines in file {file_name}\n===\n\n",
lines_displayed, num_total_lines, file_name,
) )
} }

View File

@@ -734,7 +734,7 @@ pub fn is_timeline_ready(
let note = ndb.get_note_by_key(&txn, note_key).expect("note"); let note = ndb.get_note_by_key(&txn, note_key).expect("note");
let add_pk = timeline.kind.pubkey().map(|pk| pk.bytes()); let add_pk = timeline.kind.pubkey().map(|pk| pk.bytes());
hybrid_contacts_filter(&note, add_pk, with_hashtags).map_err(Into::into) hybrid_contacts_filter(&note, add_pk, with_hashtags)
}; };
// TODO: into_follow_filter is hardcoded to contact lists, let's generalize // TODO: into_follow_filter is hardcoded to contact lists, let's generalize

View File

@@ -679,7 +679,7 @@ pub fn render_add_column_routes(
// TODO: spin off the list search here instead // TODO: spin off the list search here instead
ui.label(format!("error: could not find {:?}", list_kind)); ui.label(format!("error: could not find {list_kind:?}"));
} }
} }
}, },

View File

@@ -139,7 +139,7 @@ fn show_warnings(ui: &mut Ui, warn_no_icon: bool, warn_no_title: bool) {
ui.add( ui.add(
egui::Label::new( egui::Label::new(
RichText::new(format!("Please {}.", message)).color(ui.visuals().error_fg_color), RichText::new(format!("Please {message}.")).color(ui.visuals().error_fg_color),
) )
.wrap(), .wrap(),
); );

View File

@@ -121,12 +121,9 @@ impl<'a> EditProfileView<'a> {
ui.colored_label( ui.colored_label(
ui.visuals().noninteractive().fg_stroke.color, ui.visuals().noninteractive().fg_stroke.color,
RichText::new(if use_domain { RichText::new(if use_domain {
format!("\"{}\" will be used for identification", suffix) format!("\"{suffix}\" will be used for identification")
} else { } else {
format!( format!("\"{prefix}\" at \"{suffix}\" will be used for identification")
"\"{}\" at \"{}\" will be used for identification",
prefix, suffix
)
}), }),
); );
}); });

View File

@@ -188,9 +188,9 @@ impl fmt::Display for ToolCallError {
match self { match self {
ToolCallError::EmptyName => write!(f, "the tool name was empty"), ToolCallError::EmptyName => write!(f, "the tool name was empty"),
ToolCallError::EmptyArgs => write!(f, "no arguments were provided"), ToolCallError::EmptyArgs => write!(f, "no arguments were provided"),
ToolCallError::NotFound(ref name) => write!(f, "tool '{}' not found", name), ToolCallError::NotFound(ref name) => write!(f, "tool '{name}' not found"),
ToolCallError::ArgParseFailure(ref msg) => { ToolCallError::ArgParseFailure(ref msg) => {
write!(f, "failed to parse arguments: {}", msg) write!(f, "failed to parse arguments: {msg}")
} }
} }
} }
@@ -375,8 +375,7 @@ impl PresentNotesCall {
Ok(ToolCalls::PresentNotes(PresentNotesCall { note_ids })) Ok(ToolCalls::PresentNotes(PresentNotesCall { note_ids }))
} }
Err(e) => Err(ToolCallError::ArgParseFailure(format!( Err(e) => Err(ToolCallError::ArgParseFailure(format!(
"{}, error: {}", "{args}, error: {e}"
args, e
))), ))),
} }
} }
@@ -476,8 +475,7 @@ impl QueryCall {
match serde_json::from_str::<QueryCall>(args) { match serde_json::from_str::<QueryCall>(args) {
Ok(call) => Ok(ToolCalls::Query(call)), Ok(call) => Ok(ToolCalls::Query(call)),
Err(e) => Err(ToolCallError::ArgParseFailure(format!( Err(e) => Err(ToolCallError::ArgParseFailure(format!(
"{}, error: {}", "{args}, error: {e}"
args, e
))), ))),
} }
} }

View File

@@ -285,7 +285,7 @@ impl<'a> DaveUi<'a> {
} }
} }
ToolCalls::Invalid(err) => { ToolCalls::Invalid(err) => {
ui.label(format!("invalid tool call: {:?}", err)); ui.label(format!("invalid tool call: {err:?}"));
} }
ToolCalls::Query(search_call) => { ToolCalls::Query(search_call) => {
ui.allocate_ui_with_layout( ui.allocate_ui_with_layout(

View File

@@ -169,7 +169,7 @@ fn parse_img_response(
let dyn_image = image::load_from_memory(&response.bytes)?; let dyn_image = image::load_from_memory(&response.bytes)?;
Ok(process_pfp_bitmap(imgtyp, dyn_image)) Ok(process_pfp_bitmap(imgtyp, dyn_image))
} else { } else {
Err(format!("Expected image, found content-type {:?}", content_type).into()) Err(format!("Expected image, found content-type {content_type:?}").into())
} }
} }
@@ -328,7 +328,7 @@ fn generate_animation_frame(
TextureFrame { TextureFrame {
delay, delay,
texture: ctx.load_texture(format!("{}{}", url, index), color_img, Default::default()), texture: ctx.load_texture(format!("{url}{index}"), color_img, Default::default()),
} }
} }

View File

@@ -69,7 +69,7 @@ fn render_client(ui: &mut egui::Ui, note_cache: &mut NoteCache, note: &Note) {
match cached_note.client.as_deref() { match cached_note.client.as_deref() {
Some(client) if !client.is_empty() => { Some(client) if !client.is_empty() => {
ui.horizontal(|ui| { ui.horizontal(|ui| {
secondary_label(ui, format!("via {}", client)); secondary_label(ui, format!("via {client}"));
}); });
} }
_ => return, _ => return,

View File

@@ -31,7 +31,7 @@ pub fn display_name_widget<'a>(
let username_resp = name.username.map(|username| { let username_resp = name.username.map(|username| {
ui.add( ui.add(
Label::new( Label::new(
RichText::new(format!("@{}", username)) RichText::new(format!("@{username}"))
.size(16.0) .size(16.0)
.color(crate::colors::MID_GRAY), .color(crate::colors::MID_GRAY),
) )