From 9a60751a901f568bdeb154c4115235d4f3a0f8b9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 20 Mar 2026 21:54:29 +0800 Subject: Apply clippy suggestions and improve code quality --- systems/_asset/src/rw.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'systems/_asset/src/rw.rs') diff --git a/systems/_asset/src/rw.rs b/systems/_asset/src/rw.rs index 9a46144..7595138 100644 --- a/systems/_asset/src/rw.rs +++ b/systems/_asset/src/rw.rs @@ -1,17 +1,17 @@ -use std::path::PathBuf; +use std::path::Path; use crate::error::{DataReadError, DataWriteError}; pub trait RWData { /// Implement read logic /// Given a path, return the specific data - fn read(path: &PathBuf) -> impl Future> + Send + Sync; + fn read(path: &Path) -> impl Future> + Send + Sync; /// Implement write logic /// Given data and a path, write to the filesystem fn write( data: DataType, - path: &PathBuf, + path: &Path, ) -> impl Future> + Send + Sync; /// Provide test data @@ -42,10 +42,10 @@ pub struct FooData { } impl RWData for FooData { - async fn read(path: &PathBuf) -> Result { + async fn read(path: &Path) -> Result { let content = tokio::fs::read_to_string(path) .await - .map_err(|e| DataReadError::IoError(e))?; + .map_err(DataReadError::IoError)?; let parts: Vec<&str> = content.split('=').collect(); if parts.len() != 2 { return Err(DataReadError::ParseError("Invalid format".to_string())); @@ -57,11 +57,11 @@ impl RWData for FooData { Ok(FooData { age, name }) } - async fn write(data: FooData, path: &PathBuf) -> Result<(), DataWriteError> { + async fn write(data: FooData, path: &Path) -> Result<(), DataWriteError> { let content = format!("{}={}", data.name, data.age); tokio::fs::write(path, content) .await - .map_err(|e| DataWriteError::IoError(e))?; + .map_err(DataWriteError::IoError)?; Ok(()) } @@ -75,6 +75,6 @@ impl RWData for FooData { fn verify_data(data_a: FooData, data_b: FooData) -> bool { crate::ensure_eq!(data_a.age, data_b.age); crate::ensure_eq!(data_a.name, data_b.name); - return true; + true } } -- cgit