Fix up compiler issues.

This commit is contained in:
Lyle Mantooth 2022-05-24 22:53:15 -04:00
parent 5f8f1b5655
commit c81348fb10
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789
3 changed files with 22 additions and 18 deletions

8
Cargo.lock generated
View file

@ -13,7 +13,7 @@ name = "bin_comp"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"serde", "enemize",
"serde_json", "serde_json",
"tempfile", "tempfile",
] ]
@ -31,10 +31,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "enemize-rs" name = "enemize"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"md5", "anyhow",
"serde",
"serde_json",
] ]
[[package]] [[package]]

View file

@ -1,9 +1,11 @@
[package] [package]
name = "enemize-rs" name = "enemize"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = 1.0, features = ["derive"] } anyhow = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -1,40 +1,40 @@
use std::io::Read; use std::fs::File;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use serde::Serialize; use serde::{Deserialize, Serialize};
pub mod rom; pub mod rom;
#[derive(Serialize)] #[derive(Deserialize, Serialize)]
pub struct Patch { pub struct Patch {
pub address: usize, pub address: usize,
pub patch_data: Vec<u8>, pub patch_data: Vec<u8>,
} }
#[derive(Serialize)] #[derive(Deserialize, Serialize)]
pub struct PatchSet { pub struct PatchSet {
filename: PathBuf, filename: PathBuf,
patches: Vec<Patch> patches: Vec<Patch>,
} }
impl PatchSet { impl PatchSet {
pub fn load(filename: Path) -> Result<PatchSet, anyhow::Error> { pub fn load(filename: &Path) -> Result<PatchSet, anyhow::Error> {
let patches = { let patches = {
let mut file = File::open(filename)?; let file = File::open(filename)?;
let mut buffer = std::io::BufReader::new(file); let buffer = std::io::BufReader::new(file);
serde_json::from_reader(buffer)? serde_json::from_reader(buffer)?
}; };
PatchSet { Ok(PatchSet {
filename: filename.into(), filename: filename.into(),
patches: patches patches: patches,
} })
} }
pub fn filename(&self) -> Path { pub fn filename(&self) -> &Path {
self.filename.as_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 { for patch in self.patches {
rom.patch_data(patch); rom.patch_data(patch);
} }