summaryrefslogtreecommitdiff
path: root/systems/asset/src/rw.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-11 21:44:05 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-11 21:44:05 +0800
commit762e3119401fbee25ec18fee2ff220d9b12d48e8 (patch)
tree26dee88ae37f7d184b693a1a97dad0c89fd0db66 /systems/asset/src/rw.rs
parent2f10e0d94c61916dd36a03df2576223b135b6ccd (diff)
Add sheet system and reorganize workspace
- Add new "sheet" crate to workspace - Rename "systems/asset" to "systems/_asset" - Reorder workspace members and dependencies for clarity - Update constants with new paths for auth and rules - Add conditional compilation for system module
Diffstat (limited to 'systems/asset/src/rw.rs')
-rw-r--r--systems/asset/src/rw.rs85
1 files changed, 0 insertions, 85 deletions
diff --git a/systems/asset/src/rw.rs b/systems/asset/src/rw.rs
deleted file mode 100644
index 784d44d..0000000
--- a/systems/asset/src/rw.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-use std::path::PathBuf;
-
-use crate::error::{DataReadError, DataWriteError};
-
-pub trait RWData<DataType> {
- type DataType;
-
- /// Implement read logic
- /// Given a path, return the specific data
- fn read(path: &PathBuf) -> impl Future<Output = Result<DataType, DataReadError>> + Send + Sync;
-
- /// Implement write logic
- /// Given data and a path, write to the filesystem
- fn write(
- data: DataType,
- path: &PathBuf,
- ) -> impl Future<Output = Result<(), DataWriteError>> + Send + Sync;
-
- /// Provide test data
- fn test_data() -> DataType;
-
- /// Given two sets of data, determine if they are equal
- ///
- /// Add RWDataTest derive to your struct to automatically generate tests
- /// ```ignore
- /// #[derive(RWDataTest)]
- /// struct FooData;
- /// ```
- fn verify_data(data_a: DataType, data_b: DataType) -> bool;
-}
-
-#[macro_export]
-macro_rules! ensure_eq {
- ($a:expr, $b:expr) => {
- if $a != $b {
- return false;
- }
- };
-}
-
-// Test Data
-pub struct FooData {
- pub age: i32,
- pub name: String,
-}
-
-impl RWData<FooData> for FooData {
- type DataType = FooData;
-
- async fn read(path: &PathBuf) -> Result<FooData, DataReadError> {
- let content = tokio::fs::read_to_string(path)
- .await
- .map_err(|e| DataReadError::IoError(e))?;
- let parts: Vec<&str> = content.split('=').collect();
- if parts.len() != 2 {
- return Err(DataReadError::ParseError("Invalid format".to_string()));
- }
- let name = parts[0].to_string();
- let age: i32 = parts[1]
- .parse()
- .map_err(|_| DataReadError::ParseError("Invalid age".to_string()))?;
- Ok(FooData { age, name })
- }
-
- async fn write(data: FooData, path: &PathBuf) -> Result<(), DataWriteError> {
- let content = format!("{}={}", data.name, data.age);
- tokio::fs::write(path, content)
- .await
- .map_err(|e| DataWriteError::IoError(e))?;
- Ok(())
- }
-
- fn test_data() -> FooData {
- FooData {
- age: 24,
- name: "OneOneFourFiveOneFour".to_string(),
- }
- }
-
- 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;
- }
-}