Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[style] Simplify work with Result<T> #164

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions emulator/src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ impl ZiskEmulator {
let riscv2zisk = Riscv2zisk::new(elf_filename, String::new(), String::new(), String::new());

// Convert program to rom
let zisk_rom = riscv2zisk.run();
if zisk_rom.is_err() {
return Err(ZiskEmulatorErr::Unknown(zisk_rom.err().unwrap().to_string()));
}
let zisk_rom = riscv2zisk.run().map_err(|err| ZiskEmulatorErr::Unknown(err.to_string()))?;

Self::process_rom(&zisk_rom.unwrap(), inputs, options, callback)
Self::process_rom(&zisk_rom, inputs, options, callback)
}

fn process_rom_file(
Expand Down Expand Up @@ -314,14 +311,9 @@ impl Emulator for ZiskEmulator {
if options.rom.is_some() {
let rom_filename = options.rom.clone().unwrap();

let metadata = fs::metadata(&rom_filename);
if metadata.is_err() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file does not exist",
)));
}

let metadata = metadata.unwrap();
let metadata = fs::metadata(&rom_filename).map_err(|_| {
ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new("ROM file does not exist"))
})?;
if metadata.is_dir() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ROM file must be a file",
Expand All @@ -332,14 +324,9 @@ impl Emulator for ZiskEmulator {
} else {
let elf_filename = options.elf.clone().unwrap();

let metadata = fs::metadata(&elf_filename);
if metadata.is_err() {
return Err(ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new(
"ELF file does not exist",
)));
}

let metadata = metadata.unwrap();
let metadata = fs::metadata(&elf_filename).map_err(|_| {
ZiskEmulatorErr::WrongArguments(ErrWrongArguments::new("ELF file does not exist"))
})?;
if metadata.is_dir() {
Self::process_directory(elf_filename, &inputs, options)
} else {
Expand Down
Loading