summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-09-26 11:08:47 +0800
committer魏曹先生 <1992414357@qq.com>2025-09-26 11:08:47 +0800
commite366cade07b5408f95a0e6c268ee123e014e261c (patch)
tree5843009b3fb9df7694aa5172314011c5a3441dd5 /crates
parent47e56cc4a912c5bd7d1685f49b8ab2161f58daf0 (diff)
refactor: convert InputPackage from tuple to named struct
- Replace tuple-based InputPackage with named struct for better type safety - Add proper field names and documentation - Fix typo in InputRelativePathBuf type name - Update add_input and remove_input methods to work with new struct - Maintain serialization compatibility with derive attributes
Diffstat (limited to 'crates')
-rw-r--r--crates/vcs/src/data/sheet.rs20
-rw-r--r--crates/vcs/src/data/vault/sheets.rs6
2 files changed, 18 insertions, 8 deletions
diff --git a/crates/vcs/src/data/sheet.rs b/crates/vcs/src/data/sheet.rs
index 3acc8ff..17a0981 100644
--- a/crates/vcs/src/data/sheet.rs
+++ b/crates/vcs/src/data/sheet.rs
@@ -14,8 +14,15 @@ use crate::{
pub type SheetName = String;
pub type SheetPathBuf = PathBuf;
pub type InputName = String;
-pub type InputPackage = (InputName, Vec<(InputRaltivePathBuf, VirtualFileId)>);
-pub type InputRaltivePathBuf = PathBuf;
+pub type InputRelativePathBuf = PathBuf;
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct InputPackage {
+ /// Name of the input package
+ pub name: InputName,
+ /// Files in this input package with their relative paths and virtual file IDs
+ pub files: Vec<(InputRelativePathBuf, VirtualFileId)>,
+}
const SHEET_NAME: &str = "{sheet-name}";
@@ -62,9 +69,12 @@ impl<'a> Sheet<'a> {
pub fn add_input(
&mut self,
input_name: InputName,
- files: Vec<(InputRaltivePathBuf, VirtualFileId)>,
+ files: Vec<(InputRelativePathBuf, VirtualFileId)>,
) {
- self.data.inputs.push((input_name, files));
+ self.data.inputs.push(InputPackage {
+ name: input_name,
+ files,
+ });
}
/// Remove an input package from the sheet
@@ -72,7 +82,7 @@ impl<'a> Sheet<'a> {
self.data
.inputs
.iter()
- .position(|(name, _)| name == input_name)
+ .position(|input| input.name == *input_name)
.map(|pos| self.data.inputs.remove(pos))
}
diff --git a/crates/vcs/src/data/vault/sheets.rs b/crates/vcs/src/data/vault/sheets.rs
index ede4077..f7f6665 100644
--- a/crates/vcs/src/data/vault/sheets.rs
+++ b/crates/vcs/src/data/vault/sheets.rs
@@ -54,9 +54,9 @@ impl Vault {
// Check if it's a YAML file
if path.is_file() && path.extension().map_or(false, |ext| ext == "yaml") {
- if let Some(_file_stem) = path.file_stem().and_then(|s| s.to_str()) {
+ if let Some(file_stem) = path.file_stem().and_then(|s| s.to_str()) {
// Create a new SheetName and add it to the result list
- sheet_names.push(SheetName::new());
+ sheet_names.push(file_stem.to_string());
}
}
}
@@ -128,7 +128,7 @@ impl Vault {
// Create the sheet file
let sheet_data = SheetData {
- holder: sheet_name.clone(),
+ holder: holder.clone(),
inputs: Vec::new(),
mapping: HashMap::new(),
};