summaryrefslogtreecommitdiff
path: root/crates/vcs_data/src/data/sheet.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-06 22:10:15 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-06 22:10:15 +0800
commit759221a3001504cfd5c758e4fa70d4c2dac4e07c (patch)
treea30765b5e57ac24b0b7c7e5c81de2586e5fe07fe /crates/vcs_data/src/data/sheet.rs
parent62dd79cea8bfc0b6af95049d8a0187dd2380b09c (diff)
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
Diffstat (limited to 'crates/vcs_data/src/data/sheet.rs')
-rw-r--r--crates/vcs_data/src/data/sheet.rs21
1 files changed, 20 insertions, 1 deletions
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<MemberId>,
@@ -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
+ }
+}