Skip to content

Commit

Permalink
feat : add generics check for Machine (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Esgr0bar authored Jun 27, 2024
1 parent 4435393 commit b25ff43
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/architecture/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl MemoryRegion {
"Invalid memory region, start address is greater than or equal to end address"
));
}

Ok(Self {
region_type,
start_address,
Expand Down Expand Up @@ -157,14 +156,24 @@ impl Machine {
memory_regions: MemorySpace,
dumpfile: PathBuf,
outfolder: PathBuf,
) -> Self {
// TODO: Validate each field

Self {
) -> Result<Self> {
// Check if the dump file exists
if !dumpfile.exists() {
return Err(anyhow::anyhow!("Dump file does not exist"));
}
// Check if the output folder exists
if !outfolder.exists() {
return Err(anyhow::anyhow!("Output folder does not exist"));
}
// Check if the output folder is empty
if outfolder.read_dir()?.next().is_some() {
return Err(anyhow::anyhow!("Output folder is not empty"));
}
Ok(Self {
machine_type,
memory_regions,
dumpfile,
outfolder,
}
})
}
}

0 comments on commit b25ff43

Please sign in to comment.