From d47085e4b173490a1ce041e306574f68ae7c548c Mon Sep 17 00:00:00 2001 From: Nil Goyette Date: Tue, 6 Jun 2023 10:41:00 -0400 Subject: [PATCH 1/2] Fix all clippy warnings --- src/header.rs | 4 ++-- src/object.rs | 20 ++++---------------- src/volume/element.rs | 2 +- src/volume/inmem.rs | 4 ++-- src/volume/util.rs | 2 +- src/writer.rs | 8 ++++---- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/header.rs b/src/header.rs index 54d6e76..2321dc1 100644 --- a/src/header.rs +++ b/src/header.rs @@ -314,13 +314,13 @@ impl NiftiHeader { /// Get the qform coordinate mapping method as a validated enum. pub fn qform(&self) -> Result { FromPrimitive::from_i16(self.qform_code) - .ok_or(NiftiError::InvalidCode("qform", self.qform_code as i16)) + .ok_or(NiftiError::InvalidCode("qform", self.qform_code)) } /// Get the sform coordinate mapping method as a validated enum. pub fn sform(&self) -> Result { FromPrimitive::from_i16(self.sform_code) - .ok_or(NiftiError::InvalidCode("sform", self.sform_code as i16)) + .ok_or(NiftiError::InvalidCode("sform", self.sform_code)) } /// Ensure that the current `descrip` field is valid and is exactly equal to 80 bytes. diff --git a/src/object.rs b/src/object.rs index ab0d962..4010c93 100644 --- a/src/object.rs +++ b/src/object.rs @@ -18,18 +18,12 @@ use std::path::Path; pub use crate::util::{GzDecodedFile, MaybeGzDecodedFile}; /// Options and flags which can be used to configure how a NIfTI image is read. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct ReaderOptions { /// Whether to automatically fix value in the header fix_header: bool, } -impl Default for ReaderOptions { - fn default() -> Self { - ReaderOptions { fix_header: false } - } -} - impl ReaderOptions { /// Creates a blank new set of options ready for configuration. /// @@ -100,18 +94,12 @@ impl ReaderOptions { } /// Options and flags which can be used to configure how a NIfTI image is read and iterated. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Default, PartialEq)] pub struct ReaderStreamedOptions { /// Whether to automatically fix value in the header fix_header: bool, } -impl Default for ReaderStreamedOptions { - fn default() -> Self { - ReaderStreamedOptions { fix_header: false } - } -} - impl ReaderStreamedOptions { /// Creates a blank new set of options ready for configuration. /// @@ -509,7 +497,7 @@ impl GenericNiftiObject { }; // fetch volume (rest of file) - Ok((V::from_reader(source, &header, options)?, ext)) + Ok((V::from_reader(source, header, options)?, ext)) } fn from_file_impl( @@ -613,6 +601,6 @@ impl GenericNiftiObject { V: FromSource, { let reader = open_file_maybe_gz(path)?; - Self::from_reader_with_extensions(reader, &header, extender, options) + Self::from_reader_with_extensions(reader, header, extender, options) } } diff --git a/src/volume/element.rs b/src/volume/element.rs index 8d86308..a8e25f9 100644 --- a/src/volume/element.rs +++ b/src/volume/element.rs @@ -153,7 +153,7 @@ pub trait DataElement: let mut cursor: &[u8] = &vec; let n = align_of::(); (0..n) - .map(|_| Self::from_raw(&mut cursor, endianness.clone())) + .map(|_| Self::from_raw(&mut cursor, endianness)) .collect() } } diff --git a/src/volume/inmem.rs b/src/volume/inmem.rs index a8fdbab..a40efbe 100644 --- a/src/volume/inmem.rs +++ b/src/volume/inmem.rs @@ -159,9 +159,9 @@ impl InMemNiftiVolume { .unwrap_or(false); let file = BufReader::new(File::open(path)?); if gz { - InMemNiftiVolume::from_reader(GzDecoder::new(file), &header) + InMemNiftiVolume::from_reader(GzDecoder::new(file), header) } else { - InMemNiftiVolume::from_reader(file, &header) + InMemNiftiVolume::from_reader(file, header) } } diff --git a/src/volume/util.rs b/src/volume/util.rs index b7f396c..1c71bb7 100644 --- a/src/volume/util.rs +++ b/src/volume/util.rs @@ -20,7 +20,7 @@ pub fn coords_to_index(coords: &[u16], dim: &[u16]) -> Result { )); } - if !coords.iter().zip(dim).all(|(i, d)| *i < (*d) as u16) { + if !coords.iter().zip(dim).all(|(&i, &d)| i < d) { return Err(NiftiError::OutOfBounds(Vec::from(coords))); } diff --git a/src/writer.rs b/src/writer.rs index d44e63b..6f4bc31 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -170,7 +170,7 @@ impl<'a> WriterOptions<'a> { write_data::<_, A, _, _, _, _>(writer, data)?; } } else { - let data_file = File::create(&data_path)?; + let data_file = File::create(data_path)?; if let Some(compression_level) = self.compression { let mut writer = ByteOrdered::runtime( GzEncoder::new(header_file, compression_level), @@ -231,7 +231,7 @@ impl<'a> WriterOptions<'a> { write_data::<_, u8, _, _, _, _>(writer, data)?; } } else { - let data_file = File::create(&data_path)?; + let data_file = File::create(data_path)?; if let Some(compression_level) = self.compression { let mut writer = ByteOrdered::runtime( GzEncoder::new(header_file, compression_level), @@ -463,7 +463,7 @@ where let slice = arr_data.as_slice().unwrap(); let bytes = transmute_to_bytes(slice); let (writer, endianness) = writer.into_parts(); - let bytes = adapt_bytes::(&bytes, endianness); - writer.write_all(&*bytes)?; + let bytes = adapt_bytes::(bytes, endianness); + writer.write_all(&bytes)?; Ok(()) } From 49ff5d96d91faa74b094c5593e4523cf08b5a099 Mon Sep 17 00:00:00 2001 From: Nil Goyette Date: Tue, 6 Jun 2023 12:55:40 -0400 Subject: [PATCH 2/2] Clippy for examples and all features --- examples/gen_nifti/main.rs | 1 + src/affine.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/gen_nifti/main.rs b/examples/gen_nifti/main.rs index bee7b12..e1ceada 100644 --- a/examples/gen_nifti/main.rs +++ b/examples/gen_nifti/main.rs @@ -2,6 +2,7 @@ extern crate nifti; +#[cfg(feature = "ndarray_volumes")] use std::env; #[cfg(feature = "ndarray_volumes")] diff --git a/src/affine.rs b/src/affine.rs index 2b6946b..46a1906 100644 --- a/src/affine.rs +++ b/src/affine.rs @@ -15,7 +15,7 @@ where T: Copy + Scalar, { let translation = Vector3::new(affine[12], affine[13], affine[14]); - let affine = affine.fixed_slice::<3, 3>(0, 0).into_owned(); + let affine = affine.fixed_view::<3, 3>(0, 0).into_owned(); (affine, translation) }