mirror of
https://github.com/dnlbauer/xdrfile.git
synced 2026-09-11 14:45:31 +00:00
Merge branch 'clippy'
This commit is contained in:
@@ -64,7 +64,7 @@ impl std::error::Error for Error {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Error::CouldNotCheckNAtoms(err) => Some(err.as_ref()),
|
Error::CouldNotCheckNAtoms(err) => Some(err.as_ref()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
@@ -200,7 +200,7 @@ pub enum ErrorCode {
|
|||||||
|
|
||||||
impl ErrorCode {
|
impl ErrorCode {
|
||||||
/// True if the error is an end of file error, false otherwise
|
/// True if the error is an end of file error, false otherwise
|
||||||
pub fn is_eof(&self) -> bool {
|
pub fn is_eof(self) -> bool {
|
||||||
matches!(self, Self::ExdrEndOfFile)
|
matches!(self, Self::ExdrEndOfFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,14 +40,13 @@ impl Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Filters the frame by removing all atoms not matching the given indeces.
|
/// Filters the frame by removing all atoms not matching the given indeces.
|
||||||
pub fn filter_coords(self: &mut Frame, indeces: &[usize]) {
|
pub fn filter_coords(self: &mut Frame, indices: &[usize]) {
|
||||||
self.coords = self
|
self.coords = self
|
||||||
.coords
|
.coords
|
||||||
.iter()
|
.iter()
|
||||||
.map(|elem| elem.clone())
|
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|&(i, _)| indeces.contains(&i))
|
.filter(|(i, _)| indices.contains(i))
|
||||||
.map(|(_, elem)| elem)
|
.map(|(_, elem)| *elem)
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,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::CouldNotCheckNAtoms(Box::new(e.clone())))?,
|
Err(e) => return Err(Error::CouldNotCheckNAtoms(Box::new(e.clone()))),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reuse old frame
|
// Reuse old frame
|
||||||
|
|||||||
22
src/lib.rs
22
src/lib.rs
@@ -175,7 +175,7 @@ impl XDRFile {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Something went wrong. But the C api does not tell us what
|
// Something went wrong. But the C api does not tell us what
|
||||||
Err((path, filemode))?
|
Err((path, filemode).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,8 +275,8 @@ impl Trajectory for XTCTrajectory {
|
|||||||
.get_num_atoms()
|
.get_num_atoms()
|
||||||
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))?;
|
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))?;
|
||||||
if num_atoms != frame.coords.len() {
|
if num_atoms != frame.coords.len() {
|
||||||
Err((&*frame, num_atoms))?;
|
return Err((&*frame, num_atoms).into());
|
||||||
};
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let code = xdrfile_xtc::read_xtc(
|
let code = xdrfile_xtc::read_xtc(
|
||||||
@@ -402,7 +402,7 @@ impl Trajectory for TRRTrajectory {
|
|||||||
.get_num_atoms()
|
.get_num_atoms()
|
||||||
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))?;
|
.map_err(|e| Error::CouldNotCheckNAtoms(Box::new(e)))?;
|
||||||
if num_atoms != frame.coords.len() {
|
if num_atoms != frame.coords.len() {
|
||||||
Err((&*frame, num_atoms))?;
|
return Err((&*frame, num_atoms).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -631,21 +631,17 @@ mod tests {
|
|||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
assert_eq!(s, CString::new("test")?);
|
assert_eq!(s, CString::new("test")?);
|
||||||
}
|
}
|
||||||
Err(_) => panic!("Valid Path failed to convert to CString.")
|
Err(_) => panic!("Valid Path failed to convert to CString."),
|
||||||
}
|
}
|
||||||
|
|
||||||
// \0 in path should result in an InvalidOsStr(Some(NulError))
|
// \0 in path should result in an InvalidOsStr(Some(NulError))
|
||||||
let result = path_to_cstring(PathBuf::from("invalid/\0path"));
|
let result = path_to_cstring(PathBuf::from("invalid/\0path"));
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => panic!("Cstring conversion did not fail"),
|
Ok(_) => panic!("Cstring conversion did not fail"),
|
||||||
Err(e) => {
|
Err(e) => match e {
|
||||||
match e {
|
Error::InvalidOsStr(opt) => assert!(opt.is_some()),
|
||||||
Error::InvalidOsStr(opt) => {
|
_ => panic!("Wrong error type. (This should never happend)."),
|
||||||
assert!(opt.is_some())
|
},
|
||||||
}
|
|
||||||
_ => panic!("Wrong error type. (This should never happend).")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user