mirror of
https://github.com/dnlbauer/xdrfile.git
synced 2026-09-10 22:25:30 +00:00
reverted to single ReadNAtom error type
This commit is contained in:
@@ -26,8 +26,7 @@ pub enum Error {
|
||||
InvalidOsStr,
|
||||
/// A path could not be converted to &CStr because it had a null byte
|
||||
NullInStr(std::ffi::NulError),
|
||||
CheckNAtomsDuringRead(Box<Error>),
|
||||
CheckNAtomsDuringIter(Box<Error>),
|
||||
CouldNotCheckNAtoms(Box<Error>),
|
||||
}
|
||||
|
||||
impl Error {
|
||||
@@ -64,7 +63,7 @@ impl std::error::Error for Error {
|
||||
use Error::*;
|
||||
match &self {
|
||||
NullInStr(err) => Some(err),
|
||||
CheckNAtomsDuringRead(err) | CheckNAtomsDuringIter(err) => Some(err.as_ref()),
|
||||
CouldNotCheckNAtoms(err) => Some(err.as_ref()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -123,14 +122,10 @@ impl std::fmt::Display for Error {
|
||||
}
|
||||
InvalidOsStr => write!(f, "Paths must be valid unicode on this platform"),
|
||||
NullInStr(_err) => write!(f, "Paths cannot include null bytes"),
|
||||
CheckNAtomsDuringRead(_err) => write!(
|
||||
CouldNotCheckNAtoms(_err) => write!(
|
||||
f,
|
||||
"Failed to check number of atoms in trajectory while reading a frame"
|
||||
),
|
||||
CheckNAtomsDuringIter(_err) => write!(
|
||||
f,
|
||||
"Failed to check number of atoms in trajectory while creating iterator"
|
||||
),
|
||||
"Failed to read number of atoms in trajectory file"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ impl<T: Trajectory> TrajectoryIterator<T> {
|
||||
// It's OK to do this every frame because the result is cached by Trajectory
|
||||
let num_atoms = match &self.trajectory.get_num_atoms() {
|
||||
&Ok(n) => n,
|
||||
Err(e) => Err(Error::CheckNAtomsDuringIter(Box::new(e.clone())))?,
|
||||
Err(e) => Err(Error::CouldNotCheckNAtoms(Box::new(e.clone())))?,
|
||||
};
|
||||
|
||||
// Reuse old frame
|
||||
|
||||
@@ -218,7 +218,7 @@ impl Trajectory for XTCTrajectory {
|
||||
|
||||
let num_atoms =
|
||||
self.get_num_atoms()
|
||||
.map_err(|e| Error::CheckNAtomsDuringRead(Box::new(e)))? as usize;
|
||||
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))? as usize;
|
||||
if num_atoms != frame.coords.len() {
|
||||
Err((&*frame, num_atoms))?;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ impl Trajectory for TRRTrajectory {
|
||||
|
||||
let num_atoms =
|
||||
self.get_num_atoms()
|
||||
.map_err(|e| Error::CheckNAtomsDuringRead(Box::new(e)))? as usize;
|
||||
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))? as usize;
|
||||
if num_atoms != frame.coords.len() {
|
||||
Err((&*frame, num_atoms))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user