From ab6be7968b25afb57fc428695693484ad8576718 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 20 Mar 2026 22:21:56 +0800 Subject: Refactor code to use modern Rust idioms and fix clippy lints --- src/cmds/cmd/sheetedit.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/cmds/cmd/sheetedit.rs') diff --git a/src/cmds/cmd/sheetedit.rs b/src/cmds/cmd/sheetedit.rs index 8a18ae6..85cb616 100644 --- a/src/cmds/cmd/sheetedit.rs +++ b/src/cmds/cmd/sheetedit.rs @@ -22,7 +22,7 @@ use cmd_system_macros::exec; use just_enough_vcs::system::sheet_system::{mapping::LocalMapping, sheet::SheetData}; use just_fmt::fmt_path::{PathFormatError, fmt_path}; use rust_i18n::t; -use std::{borrow::Cow, path::PathBuf}; +use std::{borrow::Cow, path::Path}; use tokio::fs::create_dir_all; pub struct JVSheeteditCommand; @@ -58,10 +58,10 @@ async fn collect(args: &Arg, ctx: &JVCommandContext) -> Result tokio::fs::read(stdin_path) .await - .map_err(|e| CmdPrepareError::Io(e))?, + .map_err(CmdPrepareError::Io)?, (Some(file_path), None) => tokio::fs::read(file_path) .await - .map_err(|e| CmdPrepareError::Io(e))?, + .map_err(CmdPrepareError::Io)?, (None, None) => return early_cmd_output!(JVNoneOutput => JVNoneOutput), }; Ok(Collect { data }) @@ -95,7 +95,7 @@ async fn exec(input: In, collect: Collect) -> Result cmd_output!(JVNoneOutput => JVNoneOutput {}) } -fn build_template(file: &PathBuf, mappings: Vec) -> Cow<'static, str> { +fn build_template(file: &Path, mappings: Vec) -> Cow<'static, str> { let mapping_table = render_pretty_mappings(&mappings); let template = t!( "sheetedit.editor", @@ -121,13 +121,12 @@ fn render_pretty_mappings(mappings: &Vec) -> String { let mapping_str = mapping .to_string() .split(" ") - .into_iter() .map(|s| s.to_string()) .collect::>(); table.push_item(vec![ format!( " {} ", - mapping_str.get(0).unwrap_or(&String::default()) + mapping_str.first().unwrap_or(&String::default()) ), // Mapping format!("{} ", mapping_str.get(1).unwrap_or(&String::default())), // => & == format!("{} ", mapping_str.get(2).unwrap_or(&String::default())), // Index -- cgit