From 80b6cafc66c28050c4fbd3a8114d42a88f154fc0 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 12 Nov 2020 09:59:59 +0100 Subject: [PATCH] reverted to single ReadNAtom error type --- src/errors.rs | 15 +++++---------- src/iterator.rs | 2 +- src/lib.rs | 4 ++-- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 1e148cd..e874f48 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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), - CheckNAtomsDuringIter(Box), + CouldNotCheckNAtoms(Box), } 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" + ) } } } diff --git a/src/iterator.rs b/src/iterator.rs index 540a950..48ee466 100644 --- a/src/iterator.rs +++ b/src/iterator.rs @@ -50,7 +50,7 @@ impl TrajectoryIterator { // 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 diff --git a/src/lib.rs b/src/lib.rs index 83fc2dc..ebaf74a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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))?; }