From 9f9d8650fca284c02c95afd6d5cd045fd6048d79 Mon Sep 17 00:00:00 2001 From: Chen-Pang He Date: Wed, 20 Sep 2023 15:35:06 +0800 Subject: [PATCH] Ditch clones with moves --- src/tools/base64.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tools/base64.rs b/src/tools/base64.rs index db45f5e..ccd6e5c 100644 --- a/src/tools/base64.rs +++ b/src/tools/base64.rs @@ -46,7 +46,7 @@ struct AttachmentData { filename: String, } -async fn encode_attachment(attachment: &serenity::Attachment) -> anyhow::Result { +async fn encode_attachment(attachment: serenity::Attachment) -> anyhow::Result { let code = ENGINE.encode(attachment.download().await?); let code = code.as_bytes().iter().enumerate() .flat_map(|(i, c)| { @@ -56,7 +56,7 @@ async fn encode_attachment(attachment: &serenity::Attachment) -> anyhow::Result< Ok(AttachmentData { data: code.collect(), - filename: attachment.filename.clone() + ".b64.txt", + filename: attachment.filename + ".b64.txt", }) } @@ -85,7 +85,7 @@ fn encode_embed(mut embed: serenity::Embed) -> serenity::CreateEmbed { #[poise::command(context_menu_command = "Base64 encode")] pub async fn base64_encode(ctx: Context<'_>, message: serenity::Message) -> anyhow::Result<()> { let _typing = ctx.serenity_context().http.start_typing(ctx.channel_id().0); - let attachments = message.attachments.iter().map(encode_attachment); + let attachments = message.attachments.into_iter().map(encode_attachment); let attachments: Vec<_> = attachments.collect::>().collect().await; let embeds = if message.content.is_empty() { vec![] } else { message.embeds }; @@ -155,13 +155,13 @@ fn guess_extension(bytes: &[u8]) -> &'static str { }) } -async fn decode_attachment(attachment: &serenity::Attachment) -> anyhow::Result { +async fn decode_attachment(attachment: serenity::Attachment) -> anyhow::Result { let buffer = forgiving_decode(attachment.download().await?)?; let extension = guess_extension(&buffer); Ok(AttachmentData { data: buffer, - filename: attachment.filename.clone() + "." + extension, + filename: attachment.filename + "." + extension, }) } @@ -191,7 +191,7 @@ fn decode_embed(mut embed: serenity::Embed) -> anyhow::Result, message: serenity::Message) -> anyhow::Result<()> { let _typing = ctx.serenity_context().http.start_typing(ctx.channel_id().0); let text = String::from_utf8(forgiving_decode(message.content)?)?; - let attachments = message.attachments.iter().map(decode_attachment); + let attachments = message.attachments.into_iter().map(decode_attachment); let attachments: Vec<_> = attachments.collect::>().collect().await; ctx.send(|m| {