Before going crazy

This commit is contained in:
2026-01-28 18:05:50 +01:00
parent 4c633a895f
commit db5237480a
11 changed files with 459 additions and 299 deletions

View File

@@ -7,6 +7,15 @@ use serde::{Deserialize, Serialize};
use crate::project::{Bank, Project};
const VERSION: u8 = 1;
pub const EXTENSION: &str = "cagire";
pub fn ensure_extension(path: &Path) -> PathBuf {
if path.extension().map(|e| e == EXTENSION).unwrap_or(false) {
path.to_path_buf()
} else {
path.with_extension(EXTENSION)
}
}
#[derive(Serialize, Deserialize)]
struct ProjectFile {
@@ -74,11 +83,12 @@ impl From<serde_json::Error> for FileError {
}
}
pub fn save(project: &Project, path: &Path) -> Result<(), FileError> {
pub fn save(project: &Project, path: &Path) -> Result<PathBuf, FileError> {
let path = ensure_extension(path);
let file = ProjectFile::from(project);
let json = serde_json::to_string_pretty(&file)?;
fs::write(path, json)?;
Ok(())
fs::write(&path, json)?;
Ok(path)
}
pub fn load(path: &Path) -> Result<Project, FileError> {