add deserialize function
This commit is contained in:
parent
103baacb8f
commit
2851c1dfa6
@ -1,7 +1,7 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashMap, fs::File};
|
||||
use std::io::BufReader;
|
||||
use std::io::{BufReader, Read};
|
||||
|
||||
use bincode::Error;
|
||||
use ropey::Rope;
|
||||
@ -23,6 +23,23 @@ pub struct PrimitiveXml {
|
||||
pub name_to_template: HashMap<String, Template>
|
||||
}
|
||||
|
||||
pub fn load_primitive_bin(file: &str) -> Option<PrimitiveXml> {
|
||||
if let Ok(mut file) = File::open(file) {
|
||||
let mut buffer = Vec::new();
|
||||
match file.read_to_end(&mut buffer) {
|
||||
Ok(_) => {
|
||||
let deserialized_data: PrimitiveXml = bincode::deserialize(&buffer).unwrap();
|
||||
Some(deserialized_data)
|
||||
}
|
||||
Err(_) => {
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn init_parse_primitive_files(dir: &str) -> Result<PrimitiveXml, Error> {
|
||||
let mut primitive_xml = PrimitiveXml::default();
|
||||
|
Loading…
x
Reference in New Issue
Block a user