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