diff --git a/Cargo.lock b/Cargo.lock index 664456c..d1c609f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ name = "bin_comp" version = "0.1.0" dependencies = [ "anyhow", - "serde", + "enemize", "serde_json", "tempfile", ] @@ -31,10 +31,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "enemize-rs" +name = "enemize" version = "0.1.0" dependencies = [ - "md5", + "anyhow", + "serde", + "serde_json", ] [[package]] diff --git a/enemize/Cargo.toml b/enemize/Cargo.toml index c59205e..a2cf87f 100644 --- a/enemize/Cargo.toml +++ b/enemize/Cargo.toml @@ -1,9 +1,11 @@ [package] -name = "enemize-rs" +name = "enemize" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = 1.0, features = ["derive"] } +anyhow = "1" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" diff --git a/enemize/src/lib.rs b/enemize/src/lib.rs index d2ba5b0..eda29ef 100644 --- a/enemize/src/lib.rs +++ b/enemize/src/lib.rs @@ -1,40 +1,40 @@ -use std::io::Read; +use std::fs::File; use std::path::{Path, PathBuf}; -use serde::Serialize; +use serde::{Deserialize, Serialize}; pub mod rom; -#[derive(Serialize)] +#[derive(Deserialize, Serialize)] pub struct Patch { pub address: usize, pub patch_data: Vec, } -#[derive(Serialize)] +#[derive(Deserialize, Serialize)] pub struct PatchSet { filename: PathBuf, - patches: Vec + patches: Vec, } impl PatchSet { - pub fn load(filename: Path) -> Result { + pub fn load(filename: &Path) -> Result { let patches = { - let mut file = File::open(filename)?; - let mut buffer = std::io::BufReader::new(file); + let file = File::open(filename)?; + let buffer = std::io::BufReader::new(file); serde_json::from_reader(buffer)? }; - PatchSet { + Ok(PatchSet { filename: filename.into(), - patches: patches - } + patches: patches, + }) } - pub fn filename(&self) -> Path { + pub fn filename(&self) -> &Path { self.filename.as_path() } - pub fn patchRom(&self, &mut rom: RomData) { + pub fn patch_rom(self, rom: &mut RomData) { for patch in self.patches { rom.patch_data(patch); }