From 709629d5d3ab856d9711aedbe32ceaafac5369af Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 14 Mar 2026 00:17:02 +0800 Subject: Add framework system and refactor module exports --- Cargo.lock | 1 + Cargo.toml | 1 + src/lib.rs | 25 +++++++++++++++++++------ systems/_asset/src/rw.rs | 5 ----- systems/_asset/test/src/lib.rs | 2 -- systems/_framework/src/lib.rs | 7 +++++-- systems/sheet/src/sheet.rs | 10 ++++------ systems/vault/src/vault.rs | 2 +- systems/vault/src/vault/config.rs | 10 ++++------ systems/workspace/src/workspace.rs | 2 +- systems/workspace/src/workspace/config.rs | 10 ++++------ 11 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99f68cd..cf651ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -988,6 +988,7 @@ dependencies = [ "constants", "criterion", "data_struct", + "framework", "hex_display", "jvlib", "sha1_hash", diff --git a/Cargo.toml b/Cargo.toml index 20d97d4..8118e7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,6 +129,7 @@ tcp_connection = { path = "utils/tcp_connection" } asset_system = { path = "systems/_asset" } config_system = { path = "systems/_config" } constants = { path = "systems/_constants" } +framework = { path = "systems/_framework" } sheet_system = { path = "systems/sheet" } vault_system = { path = "systems/vault" } workspace_system = { path = "systems/workspace" } diff --git a/src/lib.rs b/src/lib.rs index 5609c2e..bd3f9ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,10 +16,6 @@ pub mod lib { #[cfg(feature = "lib")] pub mod system { - pub mod constants { - pub use constants::*; - } - pub mod asset_system { pub use asset_system::*; } @@ -32,8 +28,25 @@ pub mod system { pub use sheet_system::*; } - pub mod storage_system { - pub use storage_system::*; + pub mod config_system { + pub use config_system::*; + } + + pub mod constants { + pub use constants::*; + } + + pub mod space { + pub use framework::space::*; + pub use framework::space_macro::*; + } + + pub mod workspace { + pub use workspace_system::*; + } + + pub mod vault { + pub use vault_system::*; } } diff --git a/systems/_asset/src/rw.rs b/systems/_asset/src/rw.rs index 784d44d..9a46144 100644 --- a/systems/_asset/src/rw.rs +++ b/systems/_asset/src/rw.rs @@ -3,8 +3,6 @@ use std::path::PathBuf; use crate::error::{DataReadError, DataWriteError}; pub trait RWData { - type DataType; - /// Implement read logic /// Given a path, return the specific data fn read(path: &PathBuf) -> impl Future> + Send + Sync; @@ -37,7 +35,6 @@ macro_rules! ensure_eq { } }; } - // Test Data pub struct FooData { pub age: i32, @@ -45,8 +42,6 @@ pub struct FooData { } impl RWData for FooData { - type DataType = FooData; - async fn read(path: &PathBuf) -> Result { let content = tokio::fs::read_to_string(path) .await diff --git a/systems/_asset/test/src/lib.rs b/systems/_asset/test/src/lib.rs index 4aad777..4b62028 100644 --- a/systems/_asset/test/src/lib.rs +++ b/systems/_asset/test/src/lib.rs @@ -13,8 +13,6 @@ pub struct FooData { } impl RWData for FooData { - type DataType = FooData; - async fn read(path: &PathBuf) -> Result { let content = tokio::fs::read_to_string(path) .await diff --git a/systems/_framework/src/lib.rs b/systems/_framework/src/lib.rs index b0a3f9b..80507d1 100644 --- a/systems/_framework/src/lib.rs +++ b/systems/_framework/src/lib.rs @@ -1,3 +1,6 @@ pub mod space; -#[allow(unused_imports)] -pub use space_macro::*; + +pub mod space_macro { + #[allow(unused_imports)] + pub use space_macro::*; +} diff --git a/systems/sheet/src/sheet.rs b/systems/sheet/src/sheet.rs index 5ee2db7..cca2450 100644 --- a/systems/sheet/src/sheet.rs +++ b/systems/sheet/src/sheet.rs @@ -552,9 +552,7 @@ impl TryFrom<&[u8]> for SheetData { } impl RWData for SheetData { - type DataType = SheetData; - - async fn read(path: &PathBuf) -> Result { + async fn read(path: &PathBuf) -> Result { let read_data = SheetData::full_read(&mut SheetData::empty(), path).await; match read_data { Ok(_) => { @@ -573,7 +571,7 @@ impl RWData for SheetData { } async fn write( - data: Self::DataType, + data: SheetData, path: &PathBuf, ) -> Result<(), asset_system::error::DataWriteError> { let write_data = tokio::fs::write(path, data.as_bytes()).await; @@ -585,7 +583,7 @@ impl RWData for SheetData { } } - fn test_data() -> Self::DataType { + fn test_data() -> SheetData { let sheet = SheetData::empty().pack("sheet"); let mut sheet = sheet; sheet @@ -601,7 +599,7 @@ impl RWData for SheetData { sheet.unpack() } - fn verify_data(data_a: Self::DataType, data_b: Self::DataType) -> bool { + fn verify_data(data_a: SheetData, data_b: SheetData) -> bool { data_a == data_b } } diff --git a/systems/vault/src/vault.rs b/systems/vault/src/vault.rs index 262f8c5..fa3f9b5 100644 --- a/systems/vault/src/vault.rs +++ b/systems/vault/src/vault.rs @@ -3,7 +3,7 @@ use constants::vault::{ dirs::{vault_dir_changes, vault_dir_ignore_rules, vault_dir_member_root, vault_dir_refsheets}, files::vault_file_config, }; -use framework::{SpaceRootTest, space::SpaceRoot}; +use framework::{space::SpaceRoot, space_macro::SpaceRootTest}; use tokio::fs; use crate::vault::config::VaultConfig; diff --git a/systems/vault/src/vault/config.rs b/systems/vault/src/vault/config.rs index 7c4db70..329f78e 100644 --- a/systems/vault/src/vault/config.rs +++ b/systems/vault/src/vault/config.rs @@ -6,11 +6,9 @@ use serde::{Deserialize, Serialize}; pub struct VaultConfig {} impl RWData for VaultConfig { - type DataType = VaultConfig; - async fn read( path: &std::path::PathBuf, - ) -> Result { + ) -> Result { let read_config = read_config(path).await; match read_config { Ok(config) => Ok(config), @@ -21,7 +19,7 @@ impl RWData for VaultConfig { } async fn write( - data: Self::DataType, + data: VaultConfig, path: &std::path::PathBuf, ) -> Result<(), asset_system::error::DataWriteError> { let write_config = write_config(path, &data).await; @@ -35,11 +33,11 @@ impl RWData for VaultConfig { } } - fn test_data() -> Self::DataType { + fn test_data() -> VaultConfig { VaultConfig::default() } - fn verify_data(data_a: Self::DataType, data_b: Self::DataType) -> bool { + fn verify_data(data_a: VaultConfig, data_b: VaultConfig) -> bool { &data_a == &data_b } } diff --git a/systems/workspace/src/workspace.rs b/systems/workspace/src/workspace.rs index 6310146..a34a000 100644 --- a/systems/workspace/src/workspace.rs +++ b/systems/workspace/src/workspace.rs @@ -1,6 +1,6 @@ use asset_system::rw::RWData; use constants::workspace::{dirs::workspace_dir_workspace, files::workspace_file_config}; -use framework::{SpaceRootTest, space::SpaceRoot}; +use framework::{space::SpaceRoot, space_macro::SpaceRootTest}; use tokio::fs::create_dir_all; use crate::workspace::config::WorkspaceConfig; diff --git a/systems/workspace/src/workspace/config.rs b/systems/workspace/src/workspace/config.rs index 278ec08..f43dc0e 100644 --- a/systems/workspace/src/workspace/config.rs +++ b/systems/workspace/src/workspace/config.rs @@ -85,9 +85,7 @@ impl WorkspaceConfig { } impl RWData for WorkspaceConfig { - type DataType = WorkspaceConfig; - - async fn read(path: &PathBuf) -> Result { + async fn read(path: &PathBuf) -> Result { let read_config = read_config(path).await; match read_config { Ok(config) => Ok(config), @@ -98,7 +96,7 @@ impl RWData for WorkspaceConfig { } } - async fn write(data: Self::DataType, path: &PathBuf) -> Result<(), DataWriteError> { + async fn write(data: WorkspaceConfig, path: &PathBuf) -> Result<(), DataWriteError> { let write_config = write_config(path, &data).await; match write_config { Ok(_) => Ok(()), @@ -111,11 +109,11 @@ impl RWData for WorkspaceConfig { } } - fn test_data() -> Self::DataType { + fn test_data() -> WorkspaceConfig { WorkspaceConfig::default() } - fn verify_data(data_a: Self::DataType, data_b: Self::DataType) -> bool { + fn verify_data(data_a: WorkspaceConfig, data_b: WorkspaceConfig) -> bool { &data_a == &data_b } } -- cgit