I Love Cargo Clippy

This commit is contained in:
Yash Karandikar 2023-04-22 19:12:46 -05:00
parent 8828a0c44f
commit 722eb46756
2 changed files with 17 additions and 18 deletions

View file

@ -172,7 +172,7 @@ impl EventHandler for Handler {
);
sender
.send_privmsg(channel, format!("{}{}", reply_prefix, to_send))
.send_privmsg(channel, format!("{reply_prefix}{to_send}"))
.unwrap();
}
}
@ -190,7 +190,7 @@ impl EventHandler for Handler {
for chunk in StrChunks::new(line, content_limit) {
let to_send = chunk.trim_matches('\u{f}');
sender
.send_privmsg(channel, &format!("{}{}", prefix, to_send))
.send_privmsg(channel, &format!("{prefix}{to_send}"))
.unwrap();
}
}
@ -198,7 +198,7 @@ impl EventHandler for Handler {
for attachment in attachments {
sender
.send_privmsg(channel, &format!("{}{}", prefix, attachment))
.send_privmsg(channel, &format!("{prefix}{attachment}"))
.unwrap();
}
}
@ -262,7 +262,7 @@ async fn discord_to_irc_processing(
});
if let Some(display_name) = display_name {
write!(dst, "@{}", display_name).unwrap();
write!(dst, "@{display_name}").unwrap();
} else {
dst.push_str(caps.get(0).unwrap().as_str());
}
@ -332,16 +332,16 @@ async fn discord_to_irc_processing(
for event in parser {
match event {
Text(t) | Html(t) => new.push_str(&t),
Code(t) => write!(new, "`{}`", t).unwrap(),
Code(t) => write!(new, "`{t}`").unwrap(),
Start(Emphasis) => new.push('\x1D'),
Start(Strong) => new.push('\x02'),
Start(Link(_, _, _)) => {
new.push('[');
}
End(Link(_, url, title)) => {
write!(new, "]: {}", url).unwrap();
write!(new, "]: {url}").unwrap();
if !title.is_empty() {
write!(new, " ({})", title).unwrap();
write!(new, " ({title})").unwrap();
}
}
Start(List(num)) => {
@ -356,7 +356,7 @@ async fn discord_to_irc_processing(
End(List(_)) => list_level -= 1,
Start(Item) => {
let prefix = if numbered {
format!("{}.", next_num)
format!("{next_num}.")
} else {
if list_level > 1 { '◦' } else { '•' }.into()
};
@ -364,14 +364,13 @@ async fn discord_to_irc_processing(
}
End(Item) => {
if numbered {
next_num += 1
next_num += 1;
}
}
Start(BlockQuote) => new.push_str("> "),
Start(Heading(ty, _, _)) => {
write!(new, "{} \x02", "#".repeat(ty as usize)).unwrap();
}
End(Heading(_, _, _)) => new.push('\x0F'),
SoftBreak | HardBreak | End(Paragraph) => new.push('\n'),
End(_) => new.push('\x0F'),
_ => {}

View file

@ -165,7 +165,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("<{}>, {}", nickname, computed),
message: format!("<{nickname}>, {computed}"),
})?;
}
} else if let Command::JOIN(ref channel, _, _) = orig_message.command {
@ -177,7 +177,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("*{}* has joined the channel", nickname),
message: format!("*{nickname}* has joined the channel"),
})?;
} else if let Command::PART(ref channel, ref reason) = orig_message.command {
let users = unwrap_or_continue!(channel_users.get_mut(channel));
@ -191,7 +191,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("*{}* has quit ({})", nickname, reason),
message: format!("*{nickname}* has quit ({reason})"),
})?;
} else if let Command::QUIT(ref reason) = orig_message.command {
for (channel, users) in &mut channel_users {
@ -205,7 +205,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("*{}* has quit ({})", nickname, reason),
message: format!("*{nickname}* has quit ({reason})"),
})?;
}
} else if let Command::NICK(ref new_nick) = orig_message.command {
@ -218,7 +218,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("*{}* is now known as *{}*", nickname, new_nick),
message: format!("*{nickname}* is now known as *{new_nick}*"),
})?;
}
} else if let Command::TOPIC(ref channel, ref topic) = orig_message.command {
@ -232,7 +232,7 @@ pub async fn irc_loop(
send.send(QueuedMessage::Raw {
channel_id,
http: http.clone(),
message: format!("*{}* has kicked *{}* ({})", nickname, user, reason),
message: format!("*{nickname}* has kicked *{user}* ({reason})"),
})?;
}
}
@ -285,7 +285,7 @@ fn irc_to_discord_processing(
}
if WHITESPACE_RE.is_match(message).unwrap() && !PING_RE_2.is_match(message).unwrap() {
return format!("`{}`", message);
return format!("`{message}`");
}
let mut computed = message.to_owned();
@ -325,7 +325,7 @@ fn irc_to_discord_processing(
computed = computed
.strip_prefix("\x01ACTION ")
.and_then(|s| s.strip_suffix('\x01'))
.map(|s| format!("*{}*", s))
.map(|s| format!("*{s}*"))
.unwrap_or_else(|| computed); // if any step in the way fails, fall back to using computed
}