Skip to content

Commit

Permalink
Merge pull request #130 from magnusuMET/clippy
Browse files Browse the repository at this point in the history
Fix clippy lints
  • Loading branch information
magnusuMET authored Mar 1, 2024
2 parents 7a60a2f + d4c25db commit 100da01
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
32 changes: 17 additions & 15 deletions netcdf/src/attribute.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -696,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(),
)
})
}
Expand Down Expand Up @@ -889,7 +891,7 @@ fn conversion() {

impl TryFrom<AttributeValue> for u8 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<u8, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok(x),
AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion),
Expand All @@ -906,7 +908,7 @@ impl TryFrom<AttributeValue> for u8 {

impl TryFrom<AttributeValue> for i8 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<i8, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => (x).try_into().map_err(error::Error::Conversion),
AttributeValue::Schar(x) => Ok(x),
Expand All @@ -923,7 +925,7 @@ impl TryFrom<AttributeValue> for i8 {

impl TryFrom<AttributeValue> for u16 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<u16, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion),
Expand All @@ -940,7 +942,7 @@ impl TryFrom<AttributeValue> for u16 {

impl TryFrom<AttributeValue> for i16 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<i16, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => Ok((x).into()),
Expand All @@ -956,7 +958,7 @@ impl TryFrom<AttributeValue> for i16 {
}
impl TryFrom<AttributeValue> for u32 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<u32, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion),
Expand All @@ -972,7 +974,7 @@ impl TryFrom<AttributeValue> for u32 {
}
impl TryFrom<AttributeValue> for i32 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<i32, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => Ok((x).into()),
Expand All @@ -988,7 +990,7 @@ impl TryFrom<AttributeValue> for i32 {
}
impl TryFrom<AttributeValue> for u64 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<u64, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => (x).try_into().map_err(error::Error::Conversion),
Expand All @@ -1004,7 +1006,7 @@ impl TryFrom<AttributeValue> for u64 {
}
impl TryFrom<AttributeValue> for i64 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<i64, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok((x).into()),
AttributeValue::Schar(x) => Ok((x).into()),
Expand All @@ -1020,7 +1022,7 @@ impl TryFrom<AttributeValue> for i64 {
}
impl TryFrom<AttributeValue> for f32 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<f32, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok(x as _),
AttributeValue::Schar(x) => Ok(x as _),
Expand All @@ -1038,7 +1040,7 @@ impl TryFrom<AttributeValue> for f32 {
}
impl TryFrom<AttributeValue> for f64 {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<f64, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Uchar(x) => Ok(x as _),
AttributeValue::Schar(x) => Ok(x as _),
Expand All @@ -1057,7 +1059,7 @@ impl TryFrom<AttributeValue> for f64 {

impl TryFrom<AttributeValue> for String {
type Error = error::Error;
fn try_from(attr: AttributeValue) -> Result<String, Self::Error> {
fn try_from(attr: AttributeValue) -> Result<Self, Self::Error> {
match attr {
AttributeValue::Str(s) => Ok(s),
_ => Err("Conversion not supported".into()),
Expand Down
9 changes: 5 additions & 4 deletions netcdf/src/dimension.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
8 changes: 5 additions & 3 deletions netcdf/src/error.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion netcdf/src/extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
11 changes: 6 additions & 5 deletions netcdf/src/file.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
7 changes: 4 additions & 3 deletions netcdf/src/group.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions netcdf/src/types.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
11 changes: 5 additions & 6 deletions netcdf/src/variable.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -1333,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 {
Expand Down

0 comments on commit 100da01

Please sign in to comment.