New NumAtomsOutOfRange error variant

This commit is contained in:
Josh Mitchell
2020-11-15 17:39:22 +11:00
parent 9a4f27aeb7
commit 4a71ed001c
2 changed files with 9 additions and 6 deletions

View File

@@ -327,8 +327,7 @@ impl Trajectory for XTCTrajectory {
if let Some(err) = check_code(code, ErrorTask::ReadNumAtoms) {
Err(err)
} else {
Ok(usize::try_from(num_atoms)
.expect("Number of atoms in file does not fit in usize"))
usize::try_from(num_atoms).map_err(|_| Error::NumAtomsOutOfRange(num_atoms))
}
}
})
@@ -458,8 +457,7 @@ impl Trajectory for TRRTrajectory {
if let Some(err) = check_code(code, ErrorTask::ReadNumAtoms) {
Err(err)
} else {
Ok(usize::try_from(num_atoms)
.expect("Number of atoms in file does not fit in usize"))
usize::try_from(num_atoms).map_err(|_| Error::NumAtomsOutOfRange(num_atoms))
}
}
})