summaryrefslogtreecommitdiff
path: root/systems/workspace
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 21:54:29 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 21:57:49 +0800
commit9a60751a901f568bdeb154c4115235d4f3a0f8b9 (patch)
tree65df323f6478bae51473a3d6471df39a596ce9c5 /systems/workspace
parenta9e5c086584d3e697188be7003f564e7e2137135 (diff)
Apply clippy suggestions and improve code quality
Diffstat (limited to 'systems/workspace')
-rw-r--r--systems/workspace/src/workspace/config.rs20
-rw-r--r--systems/workspace/src/workspace/manager.rs6
-rw-r--r--systems/workspace/src/workspace/manager/id_aliases.rs6
-rw-r--r--systems/workspace/src/workspace/manager/sheet_state.rs15
4 files changed, 22 insertions, 25 deletions
diff --git a/systems/workspace/src/workspace/config.rs b/systems/workspace/src/workspace/config.rs
index f43dc0e..a494db3 100644
--- a/systems/workspace/src/workspace/config.rs
+++ b/systems/workspace/src/workspace/config.rs
@@ -1,4 +1,4 @@
-use std::{io::Error, path::PathBuf};
+use std::{io::Error, path::Path};
use asset_system::{
RWDataTest,
@@ -85,27 +85,19 @@ impl WorkspaceConfig {
}
impl RWData<WorkspaceConfig> for WorkspaceConfig {
- async fn read(path: &PathBuf) -> Result<WorkspaceConfig, DataReadError> {
+ async fn read(path: &Path) -> Result<WorkspaceConfig, DataReadError> {
let read_config = read_config(path).await;
match read_config {
Ok(config) => Ok(config),
- Err(e) => Err(DataReadError::IoError(Error::new(
- std::io::ErrorKind::Other,
- e,
- ))),
+ Err(e) => Err(DataReadError::IoError(Error::other(e))),
}
}
- async fn write(data: WorkspaceConfig, path: &PathBuf) -> Result<(), DataWriteError> {
+ async fn write(data: WorkspaceConfig, path: &Path) -> Result<(), DataWriteError> {
let write_config = write_config(path, &data).await;
match write_config {
Ok(_) => Ok(()),
- Err(e) => {
- return Err(DataWriteError::IoError(Error::new(
- std::io::ErrorKind::Other,
- e,
- )));
- }
+ Err(e) => Err(DataWriteError::IoError(Error::other(e))),
}
}
@@ -114,6 +106,6 @@ impl RWData<WorkspaceConfig> for WorkspaceConfig {
}
fn verify_data(data_a: WorkspaceConfig, data_b: WorkspaceConfig) -> bool {
- &data_a == &data_b
+ data_a == data_b
}
}
diff --git a/systems/workspace/src/workspace/manager.rs b/systems/workspace/src/workspace/manager.rs
index fef36ab..7e8fc47 100644
--- a/systems/workspace/src/workspace/manager.rs
+++ b/systems/workspace/src/workspace/manager.rs
@@ -10,6 +10,12 @@ pub struct WorkspaceManager {
pub(crate) space: Space<Workspace>,
}
+impl Default for WorkspaceManager {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl WorkspaceManager {
pub fn new() -> Self {
WorkspaceManager {
diff --git a/systems/workspace/src/workspace/manager/id_aliases.rs b/systems/workspace/src/workspace/manager/id_aliases.rs
index a5a509c..4ce659d 100644
--- a/systems/workspace/src/workspace/manager/id_aliases.rs
+++ b/systems/workspace/src/workspace/manager/id_aliases.rs
@@ -51,7 +51,7 @@ impl WorkspaceManager {
let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?;
IndexSourceAliasesManager::write_alias(aliases_dir, local_id, remote_id)
.await
- .map_err(|e| WorkspaceOperationError::IDAliasError(e))
+ .map_err(WorkspaceOperationError::IDAliasError)
}
/// Delete a alias between local and remote IDs
@@ -59,7 +59,7 @@ impl WorkspaceManager {
let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?;
IndexSourceAliasesManager::delete_alias(aliases_dir, local_id)
.await
- .map_err(|e| WorkspaceOperationError::IDAliasError(e))
+ .map_err(WorkspaceOperationError::IDAliasError)
}
/// Check if a alias exists between local and remote IDs
@@ -67,6 +67,6 @@ impl WorkspaceManager {
let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?;
IndexSourceAliasesManager::alias_exists(aliases_dir, local_id)
.await
- .map_err(|e| WorkspaceOperationError::IDAliasError(e))
+ .map_err(WorkspaceOperationError::IDAliasError)
}
}
diff --git a/systems/workspace/src/workspace/manager/sheet_state.rs b/systems/workspace/src/workspace/manager/sheet_state.rs
index b7cd4fd..eddfa84 100644
--- a/systems/workspace/src/workspace/manager/sheet_state.rs
+++ b/systems/workspace/src/workspace/manager/sheet_state.rs
@@ -47,7 +47,7 @@ impl WorkspaceManager {
if sheet_path.exists() {
// If reading fails, treat it as if the sheet does not exist and return `None`
sheet_data.full_read(sheet_path).await.ok()?;
- return Some(sheet_data.pack(sheet_name));
+ Some(sheet_data.pack(sheet_name))
} else {
None
}
@@ -72,7 +72,7 @@ impl WorkspaceManager {
pub fn get_sheet_path(&self, sheet_name: impl AsRef<str>) -> PathBuf {
let sheet_name = sheet_name.as_ref();
self.space
- .local_path(workspace_file_sheet(&sheet_name))
+ .local_path(workspace_file_sheet(sheet_name))
// The `local_path` only produces path formatting errors.
// If the path cannot be guaranteed to be correct,
// execution should not continue, so we unwrap()
@@ -85,12 +85,11 @@ impl WorkspaceManager {
if let Ok(mut read_dir) = self.space.read_dir(workspace_dir_local_sheets()).await {
while let Some(entry) = read_dir.next_entry().await.ok().flatten() {
let path = entry.path();
- if path.is_file() {
- if let Some(file_name) = path.file_stem() {
- if let Some(name_str) = file_name.to_str() {
- sheet_names.push(name_str.to_string());
- }
- }
+ if path.is_file()
+ && let Some(file_name) = path.file_stem()
+ && let Some(name_str) = file_name.to_str()
+ {
+ sheet_names.push(name_str.to_string());
}
}
}