summaryrefslogtreecommitdiff
path: root/src/cmds/cmd/sheetedit.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
commitab6be7968b25afb57fc428695693484ad8576718 (patch)
treee4af27964f195a18a678844dbe71c0aaa182b5dc /src/cmds/cmd/sheetedit.rs
parent6b22f7b7694fce530f84ba94c65c057450cca626 (diff)
Refactor code to use modern Rust idioms and fix clippy lints
Diffstat (limited to 'src/cmds/cmd/sheetedit.rs')
-rw-r--r--src/cmds/cmd/sheetedit.rs11
1 files changed, 5 insertions, 6 deletions
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<Collect, CmdPrepa
let data = match (&args.file, &ctx.stdin_path) {
(_, Some(stdin_path)) => 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<AnyOutput, CmdExecuteError>
cmd_output!(JVNoneOutput => JVNoneOutput {})
}
-fn build_template(file: &PathBuf, mappings: Vec<LocalMapping>) -> Cow<'static, str> {
+fn build_template(file: &Path, mappings: Vec<LocalMapping>) -> 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<LocalMapping>) -> String {
let mapping_str = mapping
.to_string()
.split(" ")
- .into_iter()
.map(|s| s.to_string())
.collect::<Vec<String>>();
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