From f5e016027349f76305d2a2396f23c727330987e8 Mon Sep 17 00:00:00 2001 From: sleefd Date: Fri, 29 Mar 2024 20:01:53 +0800 Subject: [PATCH] refactor: optimize based on cargo flippy collect to fold and format to write --- Cargo.toml | 2 +- src/macos.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c354b3c..54d4631 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "lf" version = "0.1.0" authors = ["sleefd@gmail.com"] description = "locate a file in file explorer" -repsoitory = "https://github.com/reminia/lf-rs" +repository = "https://github.com/reminia/lf-rs" keywords = ["open", "focus"] edition = "2021" diff --git a/src/macos.rs b/src/macos.rs index 0decda2..7cb240c 100644 --- a/src/macos.rs +++ b/src/macos.rs @@ -1,3 +1,4 @@ +use std::fmt::Write; use std::process::Command; fn apple_script(files: &[&str]) -> String { @@ -8,10 +9,15 @@ fn apple_script(files: &[&str]) -> String { {}\n\ select selects\n\ end tell", - files - .iter() - .map(|file| format!("set end of selects to POSIX file \"{}\" as alias\n", file)) - .collect::() + files.iter().fold(String::new(), |mut acc, file| { + writeln!( + &mut acc, + "set end of selects to POSIX file \"{}\" as alias", + file + ) + .unwrap(); + acc + }) ) }