Skip to content

Commit

Permalink
Merge pull request #104 from Enet4/clippy
Browse files Browse the repository at this point in the history
Fix all clippy warnings
  • Loading branch information
Enet4 authored Jun 6, 2023
2 parents e822cdc + 49ff5d9 commit 23c69a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 27 deletions.
1 change: 1 addition & 0 deletions examples/gen_nifti/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate nifti;

#[cfg(feature = "ndarray_volumes")]
use std::env;

#[cfg(feature = "ndarray_volumes")]
Expand Down
2 changes: 1 addition & 1 deletion src/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ impl NiftiHeader {
/// Get the qform coordinate mapping method as a validated enum.
pub fn qform(&self) -> Result<XForm> {
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<XForm> {
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.
Expand Down
20 changes: 4 additions & 16 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
///
Expand Down Expand Up @@ -509,7 +497,7 @@ impl<V> GenericNiftiObject<V> {
};

// 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<P, R>(
Expand Down Expand Up @@ -613,6 +601,6 @@ impl<V> GenericNiftiObject<V> {
V: FromSource<MaybeGzDecodedFile>,
{
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)
}
}
2 changes: 1 addition & 1 deletion src/volume/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub trait DataElement:
let mut cursor: &[u8] = &vec;
let n = align_of::<Self>();
(0..n)
.map(|_| Self::from_raw(&mut cursor, endianness.clone()))
.map(|_| Self::from_raw(&mut cursor, endianness))
.collect()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/volume/inmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/volume/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn coords_to_index(coords: &[u16], dim: &[u16]) -> Result<usize> {
));
}

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)));
}

Expand Down
8 changes: 4 additions & 4 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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::<B, _>(&bytes, endianness);
writer.write_all(&*bytes)?;
let bytes = adapt_bytes::<B, _>(bytes, endianness);
writer.write_all(&bytes)?;
Ok(())
}

0 comments on commit 23c69a9

Please sign in to comment.