From 759221a3001504cfd5c758e4fa70d4c2dac4e07c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 6 Nov 2025 22:10:15 +0800 Subject: feat: Enhanced data structures and constants - Add new constants for local workspace management - Extend SheetData with write_count functionality - Simplify vault data structures - Update sheet and virtual file data handling --- crates/vcs_data/src/data/sheet.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/vcs_data/src/data/sheet.rs') diff --git a/crates/vcs_data/src/data/sheet.rs b/crates/vcs_data/src/data/sheet.rs index 69dc27d..09271d5 100644 --- a/crates/vcs_data/src/data/sheet.rs +++ b/crates/vcs_data/src/data/sheet.rs @@ -50,6 +50,9 @@ pub struct Sheet<'a> { #[derive(Default, Serialize, Deserialize, ConfigFile, Clone)] pub struct SheetData { + /// The write count of the current sheet + pub(crate) write_count: i32, + /// The holder of the current sheet, who has full operation rights to the sheet mapping pub(crate) holder: Option, @@ -89,6 +92,11 @@ impl<'a> Sheet<'a> { &self.data.mapping } + /// Get the write count of this sheet + pub fn write_count(&self) -> i32 { + self.data.write_count + } + /// Forget the holder of this sheet pub fn forget_holder(&mut self) { self.data.holder = None; @@ -263,7 +271,11 @@ impl<'a> Sheet<'a> { /// Why not use a reference? /// Because I don't want a second instance of the sheet to be kept in memory. /// If needed, please deserialize and reload it. - pub async fn persist(self) -> Result<(), std::io::Error> { + pub async fn persist(mut self) -> Result<(), std::io::Error> { + self.data.write_count += 1; + if self.data.write_count > i32::MAX { + self.data.write_count = 0; + } SheetData::write_to(&self.data, self.sheet_path()).await } @@ -384,3 +396,10 @@ impl<'a> Sheet<'a> { self.data } } + +impl SheetData { + /// Get the write count of this sheet data + pub fn write_count(&self) -> i32 { + self.write_count + } +} -- cgit