Clearer errors if get_num_atoms fails during into_iter

This commit is contained in:
Josh Mitchell
2020-11-11 16:40:37 +11:00
parent 0d887fc515
commit 6d911fae0b
2 changed files with 35 additions and 27 deletions

View File

@@ -102,7 +102,7 @@ impl FileMode {
fn path_to_cstring(path: impl AsRef<Path>) -> Result<CString> {
let s = path.as_ref().to_str().ok_or(Error::InvalidOsStr)?;
CString::new(s).map_err(Error::from)
Ok(CString::new(s)?)
}
/// Convert an error code from a C call to an Error
@@ -119,7 +119,6 @@ pub fn check_code(code: impl Into<ErrorCode>, task: ErrorTask) -> Option<Error>
}
}
/// A safe wrapper around the c implementation of an XDRFile
struct XDRFile {
xdrfile: *mut XDRFILE,
@@ -150,7 +149,7 @@ impl XDRFile {
})
} else {
// Something went wrong. But the C api does not tell us what
Err(Error::from((path, filemode)))
Err((path, filemode))?
}
}
}
@@ -221,7 +220,7 @@ impl Trajectory for XTCTrajectory {
.get_num_atoms()
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))? as usize;
if num_atoms != frame.coords.len() {
return Err(Error::from((&*frame, num_atoms)));
Err((&*frame, num_atoms))?;
}
unsafe {
@@ -340,7 +339,7 @@ impl Trajectory for TRRTrajectory {
.get_num_atoms()
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))? as usize;
if num_atoms != frame.coords.len() {
return Err(Error::from((&*frame, num_atoms)));
Err((&*frame, num_atoms))?;
}
unsafe {