From 7b7272d947b8bc24db737914b791d251ea0fcf04 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 1 Mar 2024 10:59:09 +0100 Subject: [PATCH 1/2] Extranous imports (and import order) --- netcdf/src/attribute.rs | 8 +++++--- netcdf/src/dimension.rs | 9 +++++---- netcdf/src/error.rs | 8 +++++--- netcdf/src/extent.rs | 1 - netcdf/src/file.rs | 11 ++++++----- netcdf/src/group.rs | 7 ++++--- netcdf/src/types.rs | 4 ++-- netcdf/src/variable.rs | 9 ++++----- 8 files changed, 31 insertions(+), 26 deletions(-) diff --git a/netcdf/src/attribute.rs b/netcdf/src/attribute.rs index 4508290..9c6ac50 100644 --- a/netcdf/src/attribute.rs +++ b/netcdf/src/attribute.rs @@ -1,12 +1,14 @@ //! Add and read attributes from netcdf groups and variables - #![allow(clippy::similar_names)] -use super::error; -use netcdf_sys::*; + use std::ffi::{CStr, CString}; use std::marker::PhantomData; use std::os::raw::c_char; +use netcdf_sys::*; + +use super::error; + /// Extra properties of a variable or a group can be represented /// with attributes. Primarily added with `add_attribute` on /// the variable and group diff --git a/netcdf/src/dimension.rs b/netcdf/src/dimension.rs index 0ae6005..a259661 100644 --- a/netcdf/src/dimension.rs +++ b/netcdf/src/dimension.rs @@ -1,11 +1,12 @@ //! Interact with netcdf dimensions - #![allow(clippy::similar_names)] -use super::error; -use netcdf_sys::*; -use std::convert::TryInto; + use std::marker::PhantomData; +use netcdf_sys::*; + +use super::error; + /// Represents a netcdf dimension #[derive(Debug, Clone)] pub struct Dimension<'g> { diff --git a/netcdf/src/error.rs b/netcdf/src/error.rs index 40a47c5..d308da5 100644 --- a/netcdf/src/error.rs +++ b/netcdf/src/error.rs @@ -1,12 +1,14 @@ //! Errors that can appear when interacting with netcdf files. //! This module contains conversion traits and the result type //! used in this crate. - #![allow(clippy::similar_names)] -use super::nc_type; -use netcdf_sys::nc_strerror; + use std::num::TryFromIntError; +use netcdf_sys::nc_strerror; + +use super::nc_type; + /// Various error types that can occur in this crate #[derive(Debug)] pub enum Error { diff --git a/netcdf/src/extent.rs b/netcdf/src/extent.rs index b6bb3bd..66891a7 100644 --- a/netcdf/src/extent.rs +++ b/netcdf/src/extent.rs @@ -3,7 +3,6 @@ use std::convert::Infallible; use std::convert::TryFrom; -use std::convert::TryInto; use std::iter::StepBy; use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive}; diff --git a/netcdf/src/file.rs b/netcdf/src/file.rs index a67d695..17a8029 100644 --- a/netcdf/src/file.rs +++ b/netcdf/src/file.rs @@ -1,16 +1,17 @@ //! Open, create, and append netcdf files - #![allow(clippy::similar_names)] -use crate::group::{get_parent_ncid_and_stem, try_get_ncid, try_get_parent_ncid_and_stem}; + +use std::marker::PhantomData; +use std::path; + +use netcdf_sys::*; use super::attribute::{Attribute, AttributeValue}; use super::dimension::{self, Dimension}; use super::error; use super::group::{Group, GroupMut}; use super::variable::{NcPutGet, Variable, VariableMut}; -use netcdf_sys::*; -use std::marker::PhantomData; -use std::path; +use crate::group::{get_parent_ncid_and_stem, try_get_ncid, try_get_parent_ncid_and_stem}; #[derive(Debug)] #[repr(transparent)] diff --git a/netcdf/src/group.rs b/netcdf/src/group.rs index 0f9e030..a821cb6 100644 --- a/netcdf/src/group.rs +++ b/netcdf/src/group.rs @@ -1,13 +1,14 @@ //! All netcdf items belong in the root group, which can //! be interacted with to get the underlying data +use std::marker::PhantomData; + +use netcdf_sys::*; + use super::attribute::{Attribute, AttributeValue}; use super::dimension::Dimension; use super::error; use super::variable::{NcPutGet, Variable, VariableMut}; -use netcdf_sys::*; -use std::convert::TryInto; -use std::marker::PhantomData; /// Main component of the netcdf format. Holds all variables, /// attributes, and dimensions. A group can always see the parents items, diff --git a/netcdf/src/types.rs b/netcdf/src/types.rs index 4ccd3e8..277599e 100644 --- a/netcdf/src/types.rs +++ b/netcdf/src/types.rs @@ -1,9 +1,9 @@ //! Contains functions and enums describing variable types +use netcdf_sys::*; + use super::error; use crate::with_lock; -use netcdf_sys::*; -use std::convert::TryInto; /// Basic numeric types #[derive(Copy, Clone, Debug, PartialEq, Eq)] diff --git a/netcdf/src/variable.rs b/netcdf/src/variable.rs index d3a6dc6..23aa3f0 100644 --- a/netcdf/src/variable.rs +++ b/netcdf/src/variable.rs @@ -1,20 +1,19 @@ //! Variables in the netcdf file #![allow(clippy::similar_names)] -use std::convert::TryInto; use std::ffi::{c_char, CStr}; use std::marker::PhantomData; -use std::marker::Sized; use std::mem::MaybeUninit; use std::ptr::addr_of; +#[cfg(feature = "ndarray")] +use ndarray::ArrayD; +use netcdf_sys::*; + use super::attribute::{Attribute, AttributeValue}; use super::dimension::Dimension; use super::error; use super::extent::Extents; use super::types::VariableType; -#[cfg(feature = "ndarray")] -use ndarray::ArrayD; -use netcdf_sys::*; #[allow(clippy::doc_markdown)] /// This struct defines a `netCDF` variable. From d4c25db4f606b3af659295b8772602b975286aae Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 1 Mar 2024 11:05:41 +0100 Subject: [PATCH 2/2] Other lints --- netcdf/src/attribute.rs | 24 ++++++++++++------------ netcdf/src/variable.rs | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/netcdf/src/attribute.rs b/netcdf/src/attribute.rs index 9c6ac50..ffec57d 100644 --- a/netcdf/src/attribute.rs +++ b/netcdf/src/attribute.rs @@ -698,7 +698,7 @@ impl<'a> Attribute<'a> { varid, cname.as_ptr().cast(), cstring_pointers.len(), - cstring_pointers.as_ptr() as *mut *const _, + cstring_pointers.as_ptr().cast_mut(), ) }) } @@ -891,7 +891,7 @@ fn conversion() { impl TryFrom for u8 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok(x), AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion), @@ -908,7 +908,7 @@ impl TryFrom for u8 { impl TryFrom for i8 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => (x).try_into().map_err(error::Error::Conversion), AttributeValue::Schar(x) => Ok(x), @@ -925,7 +925,7 @@ impl TryFrom for i8 { impl TryFrom for u16 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion), @@ -942,7 +942,7 @@ impl TryFrom for u16 { impl TryFrom for i16 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => Ok((x).into()), @@ -958,7 +958,7 @@ impl TryFrom for i16 { } impl TryFrom for u32 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion), @@ -974,7 +974,7 @@ impl TryFrom for u32 { } impl TryFrom for i32 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => Ok((x).into()), @@ -990,7 +990,7 @@ impl TryFrom for i32 { } impl TryFrom for u64 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion), @@ -1006,7 +1006,7 @@ impl TryFrom for u64 { } impl TryFrom for i64 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok((x).into()), AttributeValue::Schar(x) => Ok((x).into()), @@ -1022,7 +1022,7 @@ impl TryFrom for i64 { } impl TryFrom for f32 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok(x as _), AttributeValue::Schar(x) => Ok(x as _), @@ -1040,7 +1040,7 @@ impl TryFrom for f32 { } impl TryFrom for f64 { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Uchar(x) => Ok(x as _), AttributeValue::Schar(x) => Ok(x as _), @@ -1059,7 +1059,7 @@ impl TryFrom for f64 { impl TryFrom for String { type Error = error::Error; - fn try_from(attr: AttributeValue) -> Result { + fn try_from(attr: AttributeValue) -> Result { match attr { AttributeValue::Str(s) => Ok(s), _ => Err("Conversion not supported".into()), diff --git a/netcdf/src/variable.rs b/netcdf/src/variable.rs index 23aa3f0..fc8af9d 100644 --- a/netcdf/src/variable.rs +++ b/netcdf/src/variable.rs @@ -1332,7 +1332,7 @@ impl<'g> VariableMut<'g> { let vlen = nc_vlen_t { len: vec.len(), - p: vec.as_ptr() as *mut _, + p: vec.as_ptr().cast_mut().cast(), }; error::checked(super::with_lock(|| unsafe {