Reorganize tree-related snapshot code

This commit is contained in:
Lucien Greathouse 2019-03-12 18:28:43 -07:00
parent 61b9e5a6a2
commit c86e25f039
3 changed files with 25 additions and 25 deletions

View file

@ -3,8 +3,6 @@ use std::{
path::{Path, PathBuf},
};
use rbx_dom_weak::RbxTree;
use librojo::{
project::ProjectNode,
snapshot_reconciler::RbxSnapshotInstance,
@ -59,28 +57,6 @@ pub fn anonymize_path(project_folder_path: &Path, path: &Path) -> PathBuf {
}
}
pub fn read_tree_by_name(path: &Path, identifier: &str) -> Option<RbxTree> {
let mut file_path = path.join(identifier);
file_path.set_extension("tree.json");
let contents = fs::read(&file_path).ok()?;
let tree: RbxTree = serde_json::from_slice(&contents)
.expect("Could not deserialize tree");
Some(tree)
}
pub fn write_tree_by_name(path: &Path, identifier: &str, tree: &RbxTree) {
let mut file_path = path.join(identifier);
file_path.set_extension("tree.json");
let mut file = File::create(file_path)
.expect("Could not open file to write tree");
serde_json::to_writer_pretty(&mut file, tree)
.expect("Could not serialize tree to file");
}
pub fn read_expected_snapshot(path: &Path) -> Option<Option<RbxSnapshotInstance<'static>>> {
let contents = fs::read(path.join(SNAPSHOT_EXPECTED_NAME)).ok()?;
let snapshot: Option<RbxSnapshotInstance<'static>> = serde_json::from_slice(&contents)