Skip to content

Use TryFrom over From #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hdf5-sys/src/h5.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! General purpose library functions
use std::mem;

pub use self::H5_index_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5a.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating HDF5 attributes
use std::mem;

use crate::internal_prelude::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5ac.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Cache functions
use std::mem;

use crate::internal_prelude::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5c.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Cache functionality
pub use self::H5C_cache_decr_mode::*;
pub use self::H5C_cache_flash_incr_mode::*;
pub use self::H5C_cache_incr_mode::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5d.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating scientific datasets
pub use self::H5D_alloc_time_t::*;
pub use self::H5D_fill_time_t::*;
pub use self::H5D_fill_value_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5e.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Functions for handling errors that occur within HDF5
use std::mem;

pub use self::H5E_direction_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5f.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating HDF5 files
use std::mem;

pub use self::H5F_close_degree_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5fd.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! File drivers
use std::mem;

pub use self::H5FD_file_image_op_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5g.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating groups of objects inside an HDF5 file
use std::mem;

pub use self::H5G_storage_type_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5i.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Manipulating object identifiers and object names
pub use self::H5I_type_t::*;

use crate::internal_prelude::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5l.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating links within an HDF5 group
use std::mem;

pub use self::H5L_type_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5mm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Memory managment
use crate::internal_prelude::*;

pub type H5MM_allocate_t =
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5o.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Manipulating objects in an HDF5 file
use std::mem;

pub use self::H5O_mcdt_search_ret_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5p.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating property lists to control HDF5 library behaviour
use crate::internal_prelude::*;

use crate::h5ac::H5AC_cache_config_t;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5pl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Programmatically controlling dynamically loaded plugins
use crate::internal_prelude::*;

#[cfg(hdf5_1_8_15)]
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5r.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating references to specific objects and data regions in an HDF5 file
pub use self::H5R_type_t::*;
#[cfg(not(hdf5_1_10_0))]
pub use H5Rdereference1 as H5Rdereference;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5s.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating dataspaces in which to store elements of a dataset
pub use self::H5S_class_t::*;
pub use self::H5S_sel_type::*;
pub use self::H5S_seloper_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5t.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Creating and manipulating datatypes which describe elements of a dataset
use std::mem;

pub use self::H5T_bkg_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5vl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Using the Virtual Object Layer
#![cfg(hdf5_1_12_0)]
use crate::internal_prelude::*;

Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/h5z.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Configuring filters that process data during I/O operation
use std::mem;

pub use self::H5Z_EDC_t::*;
Expand Down
1 change: 1 addition & 0 deletions hdf5-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Rust bindings to the `hdf5` library for reading and writing data to and from storage
#![allow(non_camel_case_types, non_snake_case, dead_code, deprecated)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::missing_safety_doc))]
Expand Down
30 changes: 20 additions & 10 deletions src/hl/container.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::convert::TryInto;
use std::fmt::{self, Debug};
use std::mem;
use std::ops::Deref;
Expand Down Expand Up @@ -67,12 +68,13 @@ impl<'a> Reader<'a> {
pub fn read_slice<T, S, D>(&self, selection: S) -> Result<Array<T, D>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
D: ndarray::Dimension,
{
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");

let selection = selection.into();
let selection = selection.try_into()?;
let obj_space = self.obj.space()?;

let out_shape = selection.out_shape(&obj_space.shape())?;
Expand Down Expand Up @@ -147,7 +149,8 @@ impl<'a> Reader<'a> {
pub fn read_slice_1d<T, S>(&self, selection: S) -> Result<Array1<T>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
{
self.read_slice(selection)
}
Expand All @@ -164,7 +167,8 @@ impl<'a> Reader<'a> {
pub fn read_slice_2d<T, S>(&self, selection: S) -> Result<Array2<T>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
{
self.read_slice(selection)
}
Expand Down Expand Up @@ -236,12 +240,13 @@ impl<'a> Writer<'a> {
where
A: Into<ArrayView<'b, T, D>>,
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
D: ndarray::Dimension,
{
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");

let selection = selection.into();
let selection = selection.try_into()?;
let obj_space = self.obj.space()?;

let out_shape = selection.out_shape(&obj_space.shape())?;
Expand Down Expand Up @@ -343,6 +348,7 @@ impl<'a> Writer<'a> {

#[repr(transparent)]
#[derive(Clone)]
/// An object which can be read or written to.
pub struct Container(Handle);

impl ObjectClass for Container {
Expand Down Expand Up @@ -467,7 +473,8 @@ impl Container {
pub fn read_slice_1d<T, S>(&self, selection: S) -> Result<Array1<T>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
{
self.as_reader().read_slice_1d(selection)
}
Expand All @@ -484,7 +491,8 @@ impl Container {
pub fn read_slice_2d<T, S>(&self, selection: S) -> Result<Array2<T>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
{
self.as_reader().read_slice_2d(selection)
}
Expand All @@ -502,7 +510,8 @@ impl Container {
pub fn read_slice<T, S, D>(&self, selection: S) -> Result<Array<T, D>>
where
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
D: ndarray::Dimension,
{
self.as_reader().read_slice(selection)
Expand Down Expand Up @@ -548,7 +557,8 @@ impl Container {
where
A: Into<ArrayView<'b, T, D>>,
T: H5Type,
S: Into<Selection>,
S: TryInto<Selection>,
Error: From<S::Error>,
D: ndarray::Dimension,
{
self.as_writer().write_slice(arr, selection)
Expand Down
Loading