style: 应用 rustfmt 格式化

整理 components、commands、entity 和 utils 中的 import 顺序、尾逗号、换行与文件末尾换行。

这保持代码风格与 rustfmt 输出一致,减少后续功能提交里的格式噪音。
This commit is contained in:
2026-05-09 22:02:15 +08:00
parent 405cdaab81
commit 02e72fc9d8
4 changed files with 47 additions and 50 deletions

View File

@@ -1,7 +1,7 @@
use crate::commands::ComponentsArgs;
use crate::entity;
use crate::utils::file;
use crate::error::Result;
use crate::utils::file;
use serde_json::{json, to_string_pretty};
use std::fs;
use std::path::PathBuf;
@@ -28,11 +28,12 @@ fn run_components(args: &ComponentsArgs) -> Result<()> {
args.geo.as_deref().unwrap_or("./model.geo.json"),
args.texture.as_deref().unwrap_or("./texture.png"),
identifier,
&project_path
&project_path,
),
_ => Err(crate::error::CliError::NotFound(
format!("组件 '{}' 不存在", args.component)
)),
_ => Err(crate::error::CliError::NotFound(format!(
"组件 '{}' 不存在",
args.component
))),
}
}
@@ -41,15 +42,17 @@ fn validate_input_files(geo: &Option<String>, texture: &Option<String>) -> Resul
let texture_path = texture.as_deref().unwrap_or("./texture.png");
if !PathBuf::from(geo_path).exists() {
return Err(crate::error::CliError::NotFound(
format!("几何文件 {} 不存在", geo_path)
));
return Err(crate::error::CliError::NotFound(format!(
"几何文件 {} 不存在",
geo_path
)));
}
if !PathBuf::from(texture_path).exists() {
return Err(crate::error::CliError::NotFound(
format!("材质文件 {} 不存在", texture_path)
));
return Err(crate::error::CliError::NotFound(format!(
"材质文件 {} 不存在",
texture_path
)));
}
Ok(())
@@ -137,12 +140,7 @@ fn create_resource_item_json(identifier: &str) -> serde_json::Value {
})
}
fn copy_assets(
res_path: &PathBuf,
geo: &str,
texture: &str,
identifier: &str,
) -> Result<()> {
fn copy_assets(res_path: &PathBuf, geo: &str, texture: &str, identifier: &str) -> Result<()> {
let f_identifier = identifier.replace(":", "_");
copy_texture(res_path, texture, &f_identifier)?;

View File

@@ -1,4 +1,4 @@
use clap::{arg, Args, Parser, Subcommand};
use clap::{Args, Parser, Subcommand, arg};
pub mod components;
pub mod create;
@@ -68,5 +68,5 @@ pub struct ComponentsArgs {
pub texture: Option<String>,
/// The item's identifier
#[arg(short, long)]
pub identifier: Option<String>
pub identifier: Option<String>,
}

View File

@@ -7,9 +7,8 @@ use std::{
pub fn read_file_to_json(path: &PathBuf) -> Result<Value> {
let content = fs::read_to_string(path).map_err(|e| io_error("读取文件", path, e))?;
serde_json::from_str(&content).map_err(|e| {
CliError::InvalidData(format!("解析 JSON '{}' 失败: {}", path.display(), e))
})
serde_json::from_str(&content)
.map_err(|e| CliError::InvalidData(format!("解析 JSON '{}' 失败: {}", path.display(), e)))
}
pub fn write_json_to_file(path: &PathBuf, value: &Value) -> Result<()> {