diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88a72e462..52fee97f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: ${{matrix.command}} - args: "${{matrix.command == 'fmt' && '--all -- --check' || '--workspace --exclude hdf5-src -- -D warnings -D clippy::cargo'}}" + args: "${{matrix.command == 'fmt' && '--all -- --check' || '--workspace --exclude hdf5-src -- -D warnings -D clippy::cargo -A clippy::multiple-crate-versions'}}" doc: # This task should mirror the procedure on docs.rs runs-on: ubuntu-latest @@ -58,8 +58,7 @@ jobs: include: - {version: hdf5@1.8} - {version: hdf5@1.10} - - {version: hdf5@1.12} - - {version: hdf5-mpi, mpi: true} + # - {version: hdf5-mpi, mpi: true} # TODO: re-enable once 1.14 support is merged in steps: - name: Checkout repository uses: actions/checkout@v2 @@ -156,13 +155,13 @@ jobs: apt: name: apt - runs-on: ubuntu-${{matrix.ubuntu}} + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: include: - - {ubuntu: 18.04, mpi: mpich, rust: beta} - - {ubuntu: 20.04, mpi: openmpi, rust: stable} + - {mpi: mpich, rust: beta} + - {mpi: openmpi, rust: stable} steps: - name: Checkout repository uses: actions/checkout@v2 @@ -236,7 +235,7 @@ jobs: msrv: name: Minimal Supported Rust Version - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: fail-fast: false steps: @@ -245,25 +244,27 @@ jobs: with: {submodules: true} - name: Install Rust uses: actions-rs/toolchain@v1 - with: {toolchain: 1.54, profile: minimal, override: true} + with: {toolchain: 1.64, profile: minimal, override: true} - name: Build and test all crates run: cargo test --workspace -vv --features=hdf5-sys/static --exclude=hdf5-derive - wine: - name: wine - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: {submodules: true} - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: {toolchain: stable, target: x86_64-pc-windows-gnu, profile: minimal, override: true} - - name: Install dependencies - run: sudo apt-get update && sudo apt install wine64 mingw-w64 - - name: Build and test - run: env CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=wine64 cargo test --features hdf5-sys/static --target x86_64-pc-windows-gnu -- --skip test_compile_fail + # # TODO: temporarily disabled until fixed (see https://github.com/aldanor/hdf5-rust/issues/241) + # wine: + # name: wine + # runs-on: ubuntu-latest + # steps: + # - name: Checkout repository + # uses: actions/checkout@v2 + # with: {submodules: true} + # - name: Install Rust + # uses: actions-rs/toolchain@v1 + # with: {toolchain: stable, target: x86_64-pc-windows-gnu, profile: minimal, override: true} + # - name: Install dependencies + # run: sudo apt-get update && sudo apt install wine64 mingw-w64 + # - name: Build and test + # run: env CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=wine64 cargo test --features hdf5-sys/static --target x86_64-pc-windows-gnu -- --skip test_compile_fail + addr_san: name: Address sanitizer runs-on: ubuntu-latest diff --git a/CHANGELOG.md b/CHANGELOG.md index cecdb32ab..e293b75bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ ### Changed - The `H5Type` derive macro now uses `proc-macro-error` to emit error messages. -- MSRV is now `1.54` following a bump in a dependency. +- MSRV is now `1.64.0` and Rust edition has now been bumped to 2021. ### Fixed @@ -21,6 +21,7 @@ - Fixed a missing symbol when building `hdf5-src` with `libz-sys`. - Fixed a bug where errors were only silenced on the main thread. - Fixed a memory leak when opening datasets. +- Avoid creating unaligned references in `H5Type` derive macro. ## 0.8.1 diff --git a/Cargo.toml b/Cargo.toml index af3f1e8bc..e307a50a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,55 +1,26 @@ -[package] -name = "hdf5" +[workspace] +members = ["hdf5", "hdf5-types", "hdf5-derive", "hdf5-sys", "hdf5-src"] +default-members = ["hdf5", "hdf5-types", "hdf5-derive", "hdf5-sys"] + +[workspace.package] version = "0.8.1" # !V -authors = ["Ivan Smirnov "] +rust-version = "1.64.0" +authors = ["Ivan Smirnov ", "Magnus Ulimoen "] keywords = ["hdf5"] license = "MIT OR Apache-2.0" -readme = "README.md" -description = "Thread-safe Rust bindings for the HDF5 library." repository = "https://github.com/aldanor/hdf5-rust" homepage = "https://github.com/aldanor/hdf5-rust" -build = "build.rs" -edition = "2018" -categories = ["science", "filesystem"] - -[features] -default = [] -mpio = ["mpi-sys", "hdf5-sys/mpio"] -lzf = ["lzf-sys", "errno"] -blosc = ["blosc-sys"] -# The features with version numbers such as 1.10.3, 1.12.0 are metafeatures -# and is only available when the HDF5 library is at least this version. -# Features have_direct and have_parallel are also metafeatures and dependent -# on the HDF5 library which is linked against. - -[workspace] -members = [".", "hdf5-types", "hdf5-derive", "hdf5-sys", "hdf5-src"] -default-members = [".", "hdf5-types", "hdf5-derive", "hdf5-sys"] +edition = "2021" -[dependencies] -bitflags = "1.2" -lazy_static = "1.4" -libc = "0.2" -parking_lot = "0.11" -ndarray = "0.15" -paste = "1.0" -mpi-sys = { version = "0.1", optional = true } -errno = { version = "0.2", optional = true } -hdf5-sys = { path = "hdf5-sys", version = "0.8.1" } # !V -hdf5-types = { path = "hdf5-types", version = "0.8.1" } # !V -hdf5-derive = { path = "hdf5-derive", version = "0.8.1" } # !V -blosc-sys = { version = "0.1.1", package = "blosc-src", optional = true } -lzf-sys = { version = "0.1", optional = true } +[workspace.dependencies] +# external cfg-if = "1.0" - -[dev-dependencies] -paste = "1.0" -pretty_assertions = "1.0" -rand = { version = "0.8", features = ["small_rng"] } -regex = "1.3" -scopeguard = "1.0" -tempfile = "3.2" - -[package.metadata.docs.rs] -features = ["hdf5-sys/static", "hdf5-sys/zlib", "blosc", "lzf"] -rustdoc-args = ["--cfg", "docsrs"] +libc = "0.2" +libz-sys = { version = "1.1", default-features = false } +mpi-sys = "0.2" +regex = "1.8" +# internal +hdf5-derive = { version = "0.8.1", path = "hdf5-derive" } # !V +hdf5-src = { version = "0.8.1", path = "hdf5-src" } # !V +hdf5-sys = { version = "0.8.1", path = "hdf5-sys" } # !V +hdf5-types = { version = "0.8.1", path = "hdf5-types" } # !V diff --git a/hdf5-derive/Cargo.toml b/hdf5-derive/Cargo.toml index d39558f5d..f9bc18a1e 100644 --- a/hdf5-derive/Cargo.toml +++ b/hdf5-derive/Cargo.toml @@ -1,25 +1,26 @@ [package] name = "hdf5-derive" -version = "0.8.1" # !V -authors = ["Ivan Smirnov "] -keywords = ["hdf5"] -license = "MIT OR Apache-2.0" description = "Derive macro for HDF5 structs and enums." -repository = "https://github.com/aldanor/hdf5-rust" -homepage = "https://github.com/aldanor/hdf5-rust" -edition = "2018" -readme = "README.md" categories = ["procedural-macro-helpers"] +readme = "README.md" +version.workspace = true +rust-version.workspace = true +authors.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +edition.workspace = true [lib] proc-macro = true [dependencies] -proc-macro-error = { version = "1.0.4", default-features = false } +proc-macro-error = { version = "1.0", default-features = false } proc-macro2 = "1.0" -quote = "^1.0.2" -syn = { version = "^1.0.5", features = ["derive", "extra-traits"]} +quote = "1.0" +syn = { version = "2.0", features = ["derive", "extra-traits"]} [dev-dependencies] trybuild = "1.0" -hdf5 = { version = ">=0.7.1", path = ".." } +hdf5 = { version = ">=0.7.1", path = "../hdf5" } diff --git a/hdf5-derive/src/lib.rs b/hdf5-derive/src/lib.rs index 464b03e47..a93ceef68 100644 --- a/hdf5-derive/src/lib.rs +++ b/hdf5-derive/src/lib.rs @@ -8,8 +8,8 @@ use proc_macro2::{Ident, Span, TokenStream}; use proc_macro_error::{abort, proc_macro_error}; use quote::{quote, ToTokens}; use syn::{ - parse_macro_input, AttrStyle, Attribute, Data, DeriveInput, Expr, Fields, Index, Lit, Meta, - NestedMeta, Type, TypeGenerics, TypePath, + parse_macro_input, AttrStyle, Attribute, Data, DeriveInput, Expr, Fields, Index, LitStr, Type, + TypeGenerics, TypePath, }; #[proc_macro_derive(H5Type, attributes(hdf5))] @@ -107,55 +107,40 @@ fn is_phantom_data(ty: &Type) -> bool { } fn find_repr(attrs: &[Attribute], expected: &[&str]) -> Option { + let mut repr = None; for attr in attrs.iter() { if attr.style != AttrStyle::Outer { continue; } - let list = match attr.parse_meta() { - Ok(Meta::List(list)) => list, - _ => continue, - }; - if !list.path.get_ident().map_or(false, |ident| ident == "repr") { + if !attr.path().is_ident("repr") { continue; } - for item in list.nested.iter() { - let path = match item { - NestedMeta::Meta(Meta::Path(ref path)) => path, - _ => continue, - }; - let ident = match path.get_ident() { - Some(ident) => ident, - _ => continue, - }; - if expected.iter().any(|&s| ident == s) { - return Some(Ident::new(&ident.to_string(), Span::call_site())); + attr.parse_nested_meta(|meta| { + if expected.iter().any(|s| meta.path.is_ident(s)) { + if repr.is_some() { + abort!(meta.path, "ambiguous repr attribute"); + } else { + repr = meta.path.get_ident().cloned(); + } } - } + Ok(()) + }) + .ok()?; } - - None + repr } fn find_hdf5_rename(attrs: &[Attribute]) -> Option { - if let Some(attr) = attrs.iter().find(|a| a.path.is_ident("hdf5")) { - if let Ok(Meta::List(meta_list)) = attr.parse_meta() { - let rename_literal = meta_list.nested.iter().find_map(|n| { - if let NestedMeta::Meta(Meta::NameValue(name_value)) = n { - if name_value.path.is_ident("rename") { - return Some(&name_value.lit); - } - } - - None - }); - - if let Some(Lit::Str(renamed)) = rename_literal { - return Some(renamed.value()); - } + let mut rename = None; + let attr = attrs.iter().find(|a| a.path().is_ident("hdf5"))?; + attr.parse_nested_meta(|meta| { + if meta.path.is_ident("rename") && rename.is_none() { + rename = Some(meta.value()?.parse::()?.value()); } - } - - None + Ok(()) + }) + .ok()?; + rename } fn pluck<'a, I, F, T, S>(iter: I, func: F) -> Vec diff --git a/hdf5-src/Cargo.toml b/hdf5-src/Cargo.toml index a773fdaf7..651ad228e 100644 --- a/hdf5-src/Cargo.toml +++ b/hdf5-src/Cargo.toml @@ -1,14 +1,8 @@ [package] name = "hdf5-src" -version = "0.8.1" # !V -authors = ["Ivan Smirnov "] -keywords = ["hdf5"] license-file = "ext/hdf5/COPYING" build = "build.rs" -repository = "https://github.com/aldanor/hdf5-rust" -homepage = "https://github.com/aldanor/hdf5-rust" description = "Build script for compiling HDF5 C library from source." -edition = "2018" links = "hdf5src" readme = "README.md" categories = ["ffi"] @@ -26,6 +20,13 @@ exclude = [ "ext/hdf5/hl/tools/**", "ext/hdf5/hl/examples/**", ] +version.workspace = true +rust-version.workspace = true +authors.workspace = true +keywords.workspace = true +repository.workspace = true +homepage.workspace = true +edition.workspace = true [features] hl = [] @@ -34,7 +35,7 @@ deprecated = [] threadsafe = [] [dependencies] -libz-sys = { version = "1.0.25", features = ["static", "libc"], optional = true, default-features=false } +libz-sys = { workspace = true, optional = true, features = ["static", "libc"] } [build-dependencies] -cmake = "0.1.44" +cmake = "0.1" diff --git a/hdf5-sys/Cargo.toml b/hdf5-sys/Cargo.toml index a318eb70a..64105ff32 100644 --- a/hdf5-sys/Cargo.toml +++ b/hdf5-sys/Cargo.toml @@ -1,23 +1,24 @@ [package] name = "hdf5-sys" -version = "0.8.1" # !V -authors = ["Ivan Smirnov "] -keywords = ["hdf5"] -license = "MIT OR Apache-2.0" build = "build.rs" -repository = "https://github.com/aldanor/hdf5-rust" -homepage = "https://github.com/aldanor/hdf5-rust" description = "Native bindings to the HDF5 library." -edition = "2018" links = "hdf5" readme = "README.md" categories = ["ffi", "filesystem", "science"] +version.workspace = true +rust-version.workspace = true +authors.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +edition.workspace = true [dependencies] -libc = "0.2" -mpi-sys = { version = "0.1", optional = true } -libz-sys = { version = "1.0.25", optional = true, default-features = false } -hdf5-src = { path = "../hdf5-src", version = "0.8.1", optional = true } # !V +libc = { workspace = true } +mpi-sys = { workspace = true, optional = true } +libz-sys = { workspace = true, optional = true } +hdf5-src = { workspace = true, optional = true } # Please see README for further explanation of these feature flags [features] @@ -30,8 +31,8 @@ static = ["hdf5-src"] deprecated = ["hdf5-src/deprecated"] [build-dependencies] -libloading = "0.7" -regex = { version = "1.3", features = ["std"] } +libloading = "0.8" +regex = { workspace = true } [target.'cfg(all(unix, not(target_os = "macos")))'.build-dependencies] pkg-config = "0.3" @@ -39,7 +40,7 @@ pkg-config = "0.3" [target.'cfg(windows)'.build-dependencies] serde = "1.0" serde_derive = "1.0" -winreg = { version = "0.10", features = ["serialization-serde"]} +winreg = { version = "0.50", features = ["serialization-serde"]} [package.metadata.docs.rs] features = ["static", "zlib"] diff --git a/hdf5-sys/src/h5f.rs b/hdf5-sys/src/h5f.rs index 7bbeef9e3..0904ad822 100644 --- a/hdf5-sys/src/h5f.rs +++ b/hdf5-sys/src/h5f.rs @@ -341,8 +341,9 @@ mod hdf5_1_10_1 { use super::*; #[repr(C)] - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug, Default)] pub enum H5F_fspace_strategy_t { + #[default] H5F_FSPACE_STRATEGY_FSM_AGGR = 0, H5F_FSPACE_STRATEGY_PAGE = 1, H5F_FSPACE_STRATEGY_AGGR = 2, @@ -350,12 +351,6 @@ mod hdf5_1_10_1 { H5F_FSPACE_STRATEGY_NTYPES = 4, } - impl Default for H5F_fspace_strategy_t { - fn default() -> Self { - H5F_FSPACE_STRATEGY_FSM_AGGR - } - } - pub use self::H5F_fspace_strategy_t::*; extern "C" { diff --git a/hdf5-types/Cargo.toml b/hdf5-types/Cargo.toml index 00a47f7e2..b4adb595c 100644 --- a/hdf5-types/Cargo.toml +++ b/hdf5-types/Cargo.toml @@ -1,26 +1,27 @@ [package] name = "hdf5-types" -version = "0.8.1" # !V -authors = ["Ivan Smirnov "] -keywords = ["hdf5"] -license = "MIT OR Apache-2.0" description = "Native Rust equivalents of HDF5 types." -repository = "https://github.com/aldanor/hdf5-rust" -homepage = "https://github.com/aldanor/hdf5-rust" readme = "README.md" -edition = "2018" build = "build.rs" categories = ["encoding"] +version.workspace = true +rust-version.workspace = true +authors.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +edition.workspace = true [features] h5-alloc = [] [dependencies] -ascii = "1.0" -libc = "0.2" -hdf5-sys = { version = "0.8.1", path = "../hdf5-sys" } # !V -cfg-if = "1.0.0" +ascii = "1.1" +cfg-if = { workspace = true } +hdf5-sys = { workspace = true } +libc = { workspace = true } [dev-dependencies] quickcheck = { version = "1.0", default-features = false } -unindent = "0.1" +unindent = "0.2" diff --git a/hdf5/Cargo.toml b/hdf5/Cargo.toml new file mode 100644 index 000000000..d2073593d --- /dev/null +++ b/hdf5/Cargo.toml @@ -0,0 +1,54 @@ +[package] +name = "hdf5" +readme = "../README.md" +description = "Thread-safe Rust bindings for the HDF5 library." +build = "build.rs" +categories = ["science", "filesystem"] +version.workspace = true +rust-version.workspace = true +authors.workspace = true +keywords.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +edition.workspace = true + +[features] +default = [] +mpio = ["mpi-sys", "hdf5-sys/mpio"] +lzf = ["lzf-sys", "errno"] +blosc = ["blosc-sys"] +# The features with version numbers such as 1.10.3, 1.12.0 are metafeatures +# and is only available when the HDF5 library is at least this version. +# Features have_direct and have_parallel are also metafeatures and dependent +# on the HDF5 library which is linked against. + +[dependencies] +# external +bitflags = "2.3" +blosc-sys = { version = "0.2", package = "blosc-src", optional = true } +cfg-if = { workspace = true } +errno = { version = "0.3", optional = true } +lazy_static = "1.4" +libc = { workspace = true } +lzf-sys = { version = "0.1", optional = true } +mpi-sys = { workspace = true, optional = true } +ndarray = "0.15" +parking_lot = "0.12" +paste = "1.0" +# internal +hdf5-derive = { workspace = true } +hdf5-sys = { workspace = true } +hdf5-types = { workspace = true } + +[dev-dependencies] +paste = "1.0" +pretty_assertions = "1.3" +rand = { version = "0.8", features = ["small_rng"] } +regex = { workspace = true } +scopeguard = "1.1" +tempfile = "3.6" + +[package.metadata.docs.rs] +features = ["hdf5-sys/static", "hdf5-sys/zlib", "blosc", "lzf"] +rustdoc-args = ["--cfg", "docsrs"] diff --git a/build.rs b/hdf5/build.rs similarity index 100% rename from build.rs rename to hdf5/build.rs diff --git a/examples/chunking.rs b/hdf5/examples/chunking.rs similarity index 100% rename from examples/chunking.rs rename to hdf5/examples/chunking.rs diff --git a/examples/simple.rs b/hdf5/examples/simple.rs similarity index 100% rename from examples/simple.rs rename to hdf5/examples/simple.rs diff --git a/src/class.rs b/hdf5/src/class.rs similarity index 100% rename from src/class.rs rename to hdf5/src/class.rs diff --git a/src/dim.rs b/hdf5/src/dim.rs similarity index 100% rename from src/dim.rs rename to hdf5/src/dim.rs diff --git a/src/error.rs b/hdf5/src/error.rs similarity index 99% rename from src/error.rs rename to hdf5/src/error.rs index bc9085ff1..729347e82 100644 --- a/src/error.rs +++ b/hdf5/src/error.rs @@ -123,7 +123,7 @@ impl ErrorFrame { func: func.into(), major: major.into(), minor: minor.into(), - description: format!("{}(): {}", func, desc), + description: format!("{func}(): {desc}"), } } @@ -265,7 +265,7 @@ impl StdError for Error {} impl From for Error { fn from(err: ShapeError) -> Self { - format!("shape error: {}", err).into() + format!("shape error: {err}").into() } } diff --git a/src/globals.rs b/hdf5/src/globals.rs similarity index 100% rename from src/globals.rs rename to hdf5/src/globals.rs diff --git a/src/handle.rs b/hdf5/src/handle.rs similarity index 97% rename from src/handle.rs rename to hdf5/src/handle.rs index 4eeb05300..5cf605337 100644 --- a/src/handle.rs +++ b/hdf5/src/handle.rs @@ -20,7 +20,7 @@ impl Handle { // Drop on an invalid handle could cause closing an unrelated object // in the destructor, hence it's important to prevent the drop here. mem::forget(handle); - Err(From::from(format!("Invalid handle id: {}", id))) + Err(From::from(format!("Invalid handle id: {id}"))) } } diff --git a/src/hl.rs b/hdf5/src/hl.rs similarity index 100% rename from src/hl.rs rename to hdf5/src/hl.rs diff --git a/src/hl/attribute.rs b/hdf5/src/hl/attribute.rs similarity index 100% rename from src/hl/attribute.rs rename to hdf5/src/hl/attribute.rs diff --git a/src/hl/container.rs b/hdf5/src/hl/container.rs similarity index 99% rename from src/hl/container.rs rename to hdf5/src/hl/container.rs index 560035d57..1c371edec 100644 --- a/src/hl/container.rs +++ b/hdf5/src/hl/container.rs @@ -78,7 +78,7 @@ impl<'a> Reader<'a> { let selection = selection.try_into()?; let obj_space = self.obj.space()?; - let out_shape = selection.out_shape(&obj_space.shape())?; + let out_shape = selection.out_shape(obj_space.shape())?; let out_size: Ix = out_shape.iter().product(); let fspace = obj_space.select(selection)?; @@ -250,7 +250,7 @@ impl<'a> Writer<'a> { let selection = selection.try_into()?; let obj_space = self.obj.space()?; - let out_shape = selection.out_shape(&obj_space.shape())?; + let out_shape = selection.out_shape(obj_space.shape())?; let out_size: Ix = out_shape.iter().product(); let fspace = obj_space.select(selection)?; let view = arr.into(); @@ -392,7 +392,7 @@ impl io::Read for ByteReader { let pos = self.pos as usize; let amt = std::cmp::min(buf.len(), self.remaining_len()); let selection = Selection::new(pos..pos + amt); - let out_shape = selection.out_shape(&self.obj_space.shape())?; + let out_shape = selection.out_shape(self.obj_space.shape())?; let fspace = self.obj_space.select(selection)?; let mspace = Dataspace::try_new(&out_shape)?; h5call!(H5Dread( diff --git a/src/hl/dataset.rs b/hdf5/src/hl/dataset.rs similarity index 100% rename from src/hl/dataset.rs rename to hdf5/src/hl/dataset.rs diff --git a/src/hl/dataspace.rs b/hdf5/src/hl/dataspace.rs similarity index 99% rename from src/hl/dataspace.rs rename to hdf5/src/hl/dataspace.rs index e75b21317..58c9af2f6 100644 --- a/src/hl/dataspace.rs +++ b/hdf5/src/hl/dataspace.rs @@ -36,7 +36,7 @@ impl ObjectClass for Dataspace { fn short_repr(&self) -> Option { if let Ok(e) = self.extents() { - Some(format!("{}", e)) + Some(format!("{e}")) } else { Some("(invalid)".into()) } @@ -200,7 +200,7 @@ impl Dataspace { } pub fn select>(&self, selection: S) -> Result { - let raw_sel = selection.into().into_raw(&self.shape())?; + let raw_sel = selection.into().into_raw(self.shape())?; self.select_raw(raw_sel) } diff --git a/src/hl/datatype.rs b/hdf5/src/hl/datatype.rs similarity index 99% rename from src/hl/datatype.rs rename to hdf5/src/hl/datatype.rs index 358d3ad42..2e90febe5 100644 --- a/src/hl/datatype.rs +++ b/hdf5/src/hl/datatype.rs @@ -156,6 +156,7 @@ impl From for ByteOrder { impl Datatype { /// Get the total size of the datatype in bytes. + #[allow(clippy::unnecessary_cast)] pub fn size(&self) -> usize { h5lock!(H5Tget_size(self.id())) as usize } @@ -217,6 +218,7 @@ impl Datatype { h5lock!({ let id = self.id(); + #[allow(clippy::unnecessary_cast)] let size = H5Tget_size(id) as usize; match H5Tget_class(id) { H5T_class_t::H5T_INTEGER => { diff --git a/src/hl/extents.rs b/hdf5/src/hl/extents.rs similarity index 98% rename from src/hl/extents.rs rename to hdf5/src/hl/extents.rs index b09faf499..9c9dea06d 100644 --- a/src/hl/extents.rs +++ b/hdf5/src/hl/extents.rs @@ -18,20 +18,21 @@ pub struct Extent { impl Debug for Extent { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Extent({})", self) + write!(f, "Extent({self})") } } impl Display for Extent { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let dim = self.dim; if let Some(max) = self.max { if self.dim == max { - write!(f, "{}", self.dim) + write!(f, "{dim}") } else { - write!(f, "{}..={}", self.dim, max) + write!(f, "{dim}..={max}") } } else { - write!(f, "{}..", self.dim) + write!(f, "{dim}..") } } } @@ -190,7 +191,7 @@ impl Deref for SimpleExtents { impl Debug for SimpleExtents { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "SimpleExtents({})", self) + write!(f, "SimpleExtents({self})") } } @@ -202,7 +203,7 @@ impl Display for SimpleExtents { write!(f, "({},)", self[0]) } else { let extents = self.iter().map(ToString::to_string).collect::>().join(", "); - write!(f, "({})", extents) + write!(f, "({extents})") } } } @@ -466,7 +467,7 @@ impl Display for Extents { match self { Self::Null => write!(f, "null"), Self::Scalar => write!(f, "scalar"), - Self::Simple(ref e) => write!(f, "{}", e), + Self::Simple(ref e) => write!(f, "{e}"), } } } diff --git a/src/hl/file.rs b/hdf5/src/hl/file.rs similarity index 99% rename from src/hl/file.rs rename to hdf5/src/hl/file.rs index ddd8b8f4f..81ad839dc 100644 --- a/src/hl/file.rs +++ b/hdf5/src/hl/file.rs @@ -53,7 +53,7 @@ impl ObjectClass for File { None => String::new(), }; let mode = if self.is_read_only() { "read-only" } else { "read/write" }; - Some(format!("\"{}\" ({})", basename, mode)) + Some(format!("\"{basename}\" ({mode})")) } } @@ -227,9 +227,7 @@ impl FileBuilder { } } let filename = to_cstring( - filename - .to_str() - .ok_or_else(|| format!("Invalid UTF-8 in file name: {:?}", filename))?, + filename.to_str().ok_or_else(|| format!("Invalid UTF-8 in file name: {filename:?}"))?, )?; let flags = match mode { OpenMode::Read => H5F_ACC_RDONLY, diff --git a/src/hl/filters.rs b/hdf5/src/hl/filters.rs similarity index 99% rename from src/hl/filters.rs rename to hdf5/src/hl/filters.rs index 0c873a551..02863c3df 100644 --- a/src/hl/filters.rs +++ b/hdf5/src/hl/filters.rs @@ -553,12 +553,12 @@ pub(crate) fn validate_filters(filters: &[Filter], type_class: H5T_class_t) -> R } _ => fail!("Can only use scale-offset with ints/floats, got: {:?}", type_class), } - } else if let Filter::SZip(_, _) = filter { + } else if matches!(filter, Filter::SZip(_, _)) { // https://github.com/h5py/h5py/issues/953 if map.contains_key(&H5Z_FILTER_FLETCHER32) { fail!("Fletcher32 filter must be placed after szip filter"); } - } else if let Filter::Shuffle = filter { + } else if matches!(filter, Filter::Shuffle) { if let Some(comp_filter) = comp_filter { fail!("Shuffle filter placed after compression filter: {:?}", comp_filter); } diff --git a/src/hl/filters/blosc.rs b/hdf5/src/hl/filters/blosc.rs similarity index 100% rename from src/hl/filters/blosc.rs rename to hdf5/src/hl/filters/blosc.rs diff --git a/src/hl/filters/lzf.rs b/hdf5/src/hl/filters/lzf.rs similarity index 100% rename from src/hl/filters/lzf.rs rename to hdf5/src/hl/filters/lzf.rs diff --git a/src/hl/group.rs b/hdf5/src/hl/group.rs similarity index 99% rename from src/hl/group.rs rename to hdf5/src/hl/group.rs index 0f5443f9e..9bcbe28c6 100644 --- a/src/hl/group.rs +++ b/hdf5/src/hl/group.rs @@ -40,7 +40,7 @@ impl ObjectClass for Group { let members = match self.len() { 0 => "empty".to_owned(), 1 => "1 member".to_owned(), - x => format!("{} members", x), + x => format!("{x} members"), }; Some(format!("\"{}\" ({})", self.name(), members)) } @@ -326,11 +326,9 @@ impl Group { let info = unsafe { info.as_ref().expect("iter_vist: null info ptr") }; let handle = Handle::try_borrow(id).expect("iter_visit: unable to create a handle"); let group = Group::from_handle(handle); - if (vtable.f)(&group, name.to_string_lossy().as_ref(), info.into(), vtable.d) { - 0 - } else { - 1 - } + let ret = + (vtable.f)(&group, name.to_string_lossy().as_ref(), info.into(), vtable.d); + i32::from(!ret) }) .unwrap_or(-1) } diff --git a/src/hl/location.rs b/hdf5/src/hl/location.rs similarity index 100% rename from src/hl/location.rs rename to hdf5/src/hl/location.rs diff --git a/src/hl/object.rs b/hdf5/src/hl/object.rs similarity index 100% rename from src/hl/object.rs rename to hdf5/src/hl/object.rs diff --git a/src/hl/plist.rs b/hdf5/src/hl/plist.rs similarity index 99% rename from src/hl/plist.rs rename to hdf5/src/hl/plist.rs index 40096a1fa..abd4da83b 100644 --- a/src/hl/plist.rs +++ b/hdf5/src/hl/plist.rs @@ -124,7 +124,7 @@ impl Display for PropertyListClass { impl From for String { fn from(v: PropertyListClass) -> Self { - format!("{}", v) + format!("{v}") } } @@ -149,7 +149,7 @@ impl FromStr for PropertyListClass { "object copy" => Ok(Self::ObjectCopy), "object create" => Ok(Self::ObjectCreate), "string create" => Ok(Self::StringCreate), - _ => fail!(format!("invalid property list class: {}", s)), + _ => fail!(format!("invalid property list class: {s}")), } } } diff --git a/src/hl/plist/common.rs b/hdf5/src/hl/plist/common.rs similarity index 97% rename from src/hl/plist/common.rs rename to hdf5/src/hl/plist/common.rs index ba594ebff..85b874879 100644 --- a/src/hl/plist/common.rs +++ b/hdf5/src/hl/plist/common.rs @@ -37,7 +37,7 @@ bitflags! { /// the object creation property list. HDF5 currently provides no mechanism to turn /// on attribute creation order tracking at object creation time and to build the /// index later. - #[derive(Default)] + #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub struct AttrCreationOrder: u32 { /// Attribute creation order is tracked but not necessarily indexed. const TRACKED = H5P_CRT_ORDER_TRACKED as _; diff --git a/src/hl/plist/dataset_access.rs b/hdf5/src/hl/plist/dataset_access.rs similarity index 100% rename from src/hl/plist/dataset_access.rs rename to hdf5/src/hl/plist/dataset_access.rs diff --git a/src/hl/plist/dataset_create.rs b/hdf5/src/hl/plist/dataset_create.rs similarity index 99% rename from src/hl/plist/dataset_create.rs rename to hdf5/src/hl/plist/dataset_create.rs index a58b2f216..56fabdfe2 100644 --- a/src/hl/plist/dataset_create.rs +++ b/hdf5/src/hl/plist/dataset_create.rs @@ -148,6 +148,7 @@ impl From for H5D_layout_t { #[cfg(feature = "1.10.0")] bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct ChunkOpts: u32 { const DONT_FILTER_PARTIAL_CHUNKS = H5D_CHUNK_DONT_FILTER_PARTIAL_CHUNKS; } diff --git a/src/hl/plist/file_access.rs b/hdf5/src/hl/plist/file_access.rs similarity index 99% rename from src/hl/plist/file_access.rs rename to hdf5/src/hl/plist/file_access.rs index 29b01df65..6d0e050bc 100644 --- a/src/hl/plist/file_access.rs +++ b/hdf5/src/hl/plist/file_access.rs @@ -195,6 +195,7 @@ impl Default for FamilyDriver { } bitflags! { + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct LogFlags: u64 { const TRUNCATE = H5FD_LOG_TRUNCATE; const META_IO = H5FD_LOG_META_IO; @@ -1760,6 +1761,7 @@ impl FileAccess { #[cfg(feature = "1.10.0")] #[doc(hidden)] + #[allow(clippy::unnecessary_cast)] pub fn get_mdc_log_options(&self) -> Result { let mut is_enabled: hbool_t = 0; let mut location_size: size_t = 0; diff --git a/src/hl/plist/file_create.rs b/hdf5/src/hl/plist/file_create.rs similarity index 99% rename from src/hl/plist/file_create.rs rename to hdf5/src/hl/plist/file_create.rs index cfe00a42e..03b105da1 100644 --- a/src/hl/plist/file_create.rs +++ b/hdf5/src/hl/plist/file_create.rs @@ -155,6 +155,7 @@ pub struct PhaseChangeInfo { bitflags! { /// Types of messages that can be stored in a shared message index. + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct SharedMessageType: u32 { /// No shared messages. const NONE = H5O_SHMESG_NONE_FLAG; diff --git a/src/hl/plist/link_create.rs b/hdf5/src/hl/plist/link_create.rs similarity index 100% rename from src/hl/plist/link_create.rs rename to hdf5/src/hl/plist/link_create.rs diff --git a/src/hl/selection.rs b/hdf5/src/hl/selection.rs similarity index 98% rename from src/hl/selection.rs rename to hdf5/src/hl/selection.rs index ad7779cc5..ce0893296 100644 --- a/src/hl/selection.rs +++ b/hdf5/src/hl/selection.rs @@ -530,43 +530,43 @@ impl From> for Selection { impl Display for SliceOrIndex { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Self::Index(index) => write!(f, "{}", index)?, + Self::Index(index) => write!(f, "{index}")?, Self::SliceTo { start, end, step, block } => { if start != 0 { - write!(f, "{}", start)?; + write!(f, "{start}")?; } write!(f, "..")?; - write!(f, "{}", end)?; + write!(f, "{end}")?; if step != 1 { - write!(f, ";{}", step)?; + write!(f, ";{step}")?; } if block != 1 { - write!(f, "(Bx{})", block)?; + write!(f, "(Bx{block})")?; } } Self::SliceCount { start, step, count, block } => { if start != 0 { - write!(f, "{}", start)?; + write!(f, "{start}")?; } - write!(f, "+{}", count)?; + write!(f, "+{count}")?; if step != 1 { - write!(f, ";{}", step)?; + write!(f, ";{step}")?; } if block != 1 { - write!(f, "(Bx{})", block)?; + write!(f, "(Bx{block})")?; } } Self::Unlimited { start, step, block } => { if start != 0 { - write!(f, "{}", start)?; + write!(f, "{start}")?; } // \u{221e} = ∞ write!(f, "..\u{221e}")?; if step != 1 { - write!(f, ";{}", step)?; + write!(f, ";{step}")?; } if block != 1 { - write!(f, "(Bx{})", block)?; + write!(f, "(Bx{block})")?; } } } @@ -719,7 +719,7 @@ where /// Turns `SliceOrIndex` into real dimensions given `dim` as the maximum dimension fn slice_info_to_raw(axis: usize, slice: &SliceOrIndex, dim: Ix) -> Result { - let err_msg = || format!("out of bounds for axis {} with size {}", axis, dim); + let err_msg = || format!("out of bounds for axis {axis} with size {dim}"); let (start, step, count, block) = match *slice { SliceOrIndex::Index(index) => { ensure!(index < dim, "Index {} {}", index, err_msg()); @@ -760,7 +760,7 @@ impl Display for Hyperslab { if i != 0 { write!(f, ", ")?; } - write!(f, "{}", s)?; + write!(f, "{s}")?; } if slice.len() == 1 { write!(f, ",")?; @@ -908,10 +908,10 @@ impl Display for Selection { if points.shape() == [0, 0] { write!(f, "[]") } else { - write!(f, "{}", points) + write!(f, "{points}") } } - Self::Hyperslab(hyper) => write!(f, "{}", hyper), + Self::Hyperslab(hyper) => write!(f, "{hyper}"), } } } diff --git a/src/lib.rs b/hdf5/src/lib.rs similarity index 100% rename from src/lib.rs rename to hdf5/src/lib.rs diff --git a/src/macros.rs b/hdf5/src/macros.rs similarity index 100% rename from src/macros.rs rename to hdf5/src/macros.rs diff --git a/src/sync.rs b/hdf5/src/sync.rs similarity index 100% rename from src/sync.rs rename to hdf5/src/sync.rs diff --git a/src/test.rs b/hdf5/src/test.rs similarity index 100% rename from src/test.rs rename to hdf5/src/test.rs diff --git a/src/util.rs b/hdf5/src/util.rs similarity index 99% rename from src/util.rs rename to hdf5/src/util.rs index 37b1bd316..c919b87eb 100644 --- a/src/util.rs +++ b/hdf5/src/util.rs @@ -15,7 +15,7 @@ pub fn string_from_cstr(string: *const c_char) -> String { pub fn to_cstring>(string: S) -> Result { let string = string.borrow(); #[allow(clippy::map_err_ignore)] - CString::new(string).map_err(|_| format!("null byte in string: {:?}", string).into()) + CString::new(string).map_err(|_| format!("null byte in string: {string:?}").into()) } /// Convert a fixed-length (possibly zero-terminated) char buffer to a string. diff --git a/rustfmt.toml b/rustfmt.toml index 016086545..e087fb650 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,4 +4,4 @@ use_try_shorthand = true empty_item_single_line = true edition = "2018" unstable_features = true -fn_args_layout = "Compressed" +fn_params_layout = "Compressed" diff --git a/tests/test_dataset.rs b/tests/test_dataset.rs index 4f02a95d4..7a7c4b159 100644 --- a/tests/test_dataset.rs +++ b/tests/test_dataset.rs @@ -5,7 +5,7 @@ use std::io::{Read, Seek, SeekFrom}; use ndarray::{s, Array1, Array2, ArrayD, IxDyn, SliceInfo}; use rand::prelude::{Rng, SeedableRng, SmallRng}; -use hdf5_types::{H5Type, TypeDescriptor}; +use hdf5_types::TypeDescriptor; mod common;