Added this wad.rs thingy

It'll hopefully let me get into more rust AND doom stuff
This commit is contained in:
2023-06-18 22:39:28 +01:00
parent 849902ce84
commit 2e92202dbb
4 changed files with 39 additions and 5 deletions

32
src/wad.rs Normal file
View File

@@ -0,0 +1,32 @@
use std::path::PathBuf;
use std::fs::File;
use std::io::BufReader;
use bincode;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct WadHeader {
pub identifier: [u8; 4],
pub num_lumps: i32,
pub file_offset_to_start: i32,
}
pub fn open_wad(path: &PathBuf) -> WadHeader {
let mut file = BufReader::new(File::open(path).unwrap());
let header: WadHeader = bincode::deserialize_from(&mut file).unwrap();
header
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_open_wad() {
let freedoom_iwad = PathBuf::from("freedoom1.wad");
let ow = open_wad(&freedoom_iwad);
assert_eq!(std::str::from_utf8(&ow.identifier).unwrap(), "IWAD");
}
}