Skip to content

Commit b762e22

Browse files
authored
Merge pull request #147 from mulimoen/feature/try_into_selection
Use TryFrom over From
2 parents 46c24e2 + 252136f commit b762e22

24 files changed

+569
-378
lines changed

hdf5-sys/src/h5.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! General purpose library functions
12
use std::mem;
23

34
pub use self::H5_index_t::*;

hdf5-sys/src/h5a.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating HDF5 attributes
12
use std::mem;
23

34
use crate::internal_prelude::*;

hdf5-sys/src/h5ac.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Cache functions
12
use std::mem;
23

34
use crate::internal_prelude::*;

hdf5-sys/src/h5c.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Cache functionality
12
pub use self::H5C_cache_decr_mode::*;
23
pub use self::H5C_cache_flash_incr_mode::*;
34
pub use self::H5C_cache_incr_mode::*;

hdf5-sys/src/h5d.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating scientific datasets
12
pub use self::H5D_alloc_time_t::*;
23
pub use self::H5D_fill_time_t::*;
34
pub use self::H5D_fill_value_t::*;

hdf5-sys/src/h5e.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Functions for handling errors that occur within HDF5
12
use std::mem;
23

34
pub use self::H5E_direction_t::*;

hdf5-sys/src/h5f.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating HDF5 files
12
use std::mem;
23

34
pub use self::H5F_close_degree_t::*;

hdf5-sys/src/h5fd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! File drivers
12
use std::mem;
23

34
pub use self::H5FD_file_image_op_t::*;

hdf5-sys/src/h5g.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating groups of objects inside an HDF5 file
12
use std::mem;
23

34
pub use self::H5G_storage_type_t::*;

hdf5-sys/src/h5i.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Manipulating object identifiers and object names
12
pub use self::H5I_type_t::*;
23

34
use crate::internal_prelude::*;

hdf5-sys/src/h5l.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating links within an HDF5 group
12
use std::mem;
23

34
pub use self::H5L_type_t::*;

hdf5-sys/src/h5mm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Memory managment
12
use crate::internal_prelude::*;
23

34
pub type H5MM_allocate_t =

hdf5-sys/src/h5o.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Manipulating objects in an HDF5 file
12
use std::mem;
23

34
pub use self::H5O_mcdt_search_ret_t::*;

hdf5-sys/src/h5p.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating property lists to control HDF5 library behaviour
12
use crate::internal_prelude::*;
23

34
use crate::h5ac::H5AC_cache_config_t;

hdf5-sys/src/h5pl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Programmatically controlling dynamically loaded plugins
12
use crate::internal_prelude::*;
23

34
#[cfg(hdf5_1_8_15)]

hdf5-sys/src/h5r.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating references to specific objects and data regions in an HDF5 file
12
pub use self::H5R_type_t::*;
23
#[cfg(not(hdf5_1_10_0))]
34
pub use H5Rdereference1 as H5Rdereference;

hdf5-sys/src/h5s.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating dataspaces in which to store elements of a dataset
12
pub use self::H5S_class_t::*;
23
pub use self::H5S_sel_type::*;
34
pub use self::H5S_seloper_t::*;

hdf5-sys/src/h5t.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Creating and manipulating datatypes which describe elements of a dataset
12
use std::mem;
23

34
pub use self::H5T_bkg_t::*;

hdf5-sys/src/h5vl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Using the Virtual Object Layer
12
#![cfg(hdf5_1_12_0)]
23
use crate::internal_prelude::*;
34

hdf5-sys/src/h5z.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Configuring filters that process data during I/O operation
12
use std::mem;
23

34
pub use self::H5Z_EDC_t::*;

hdf5-sys/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Rust bindings to the `hdf5` library for reading and writing data to and from storage
12
#![allow(non_camel_case_types, non_snake_case, dead_code, deprecated)]
23
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
34
#![cfg_attr(feature = "cargo-clippy", allow(clippy::missing_safety_doc))]

src/hl/container.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::convert::TryInto;
12
use std::fmt::{self, Debug};
23
use std::mem;
34
use std::ops::Deref;
@@ -67,12 +68,13 @@ impl<'a> Reader<'a> {
6768
pub fn read_slice<T, S, D>(&self, selection: S) -> Result<Array<T, D>>
6869
where
6970
T: H5Type,
70-
S: Into<Selection>,
71+
S: TryInto<Selection>,
72+
Error: From<S::Error>,
7173
D: ndarray::Dimension,
7274
{
7375
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");
7476

75-
let selection = selection.into();
77+
let selection = selection.try_into()?;
7678
let obj_space = self.obj.space()?;
7779

7880
let out_shape = selection.out_shape(&obj_space.shape())?;
@@ -147,7 +149,8 @@ impl<'a> Reader<'a> {
147149
pub fn read_slice_1d<T, S>(&self, selection: S) -> Result<Array1<T>>
148150
where
149151
T: H5Type,
150-
S: Into<Selection>,
152+
S: TryInto<Selection>,
153+
Error: From<S::Error>,
151154
{
152155
self.read_slice(selection)
153156
}
@@ -164,7 +167,8 @@ impl<'a> Reader<'a> {
164167
pub fn read_slice_2d<T, S>(&self, selection: S) -> Result<Array2<T>>
165168
where
166169
T: H5Type,
167-
S: Into<Selection>,
170+
S: TryInto<Selection>,
171+
Error: From<S::Error>,
168172
{
169173
self.read_slice(selection)
170174
}
@@ -236,12 +240,13 @@ impl<'a> Writer<'a> {
236240
where
237241
A: Into<ArrayView<'b, T, D>>,
238242
T: H5Type,
239-
S: Into<Selection>,
243+
S: TryInto<Selection>,
244+
Error: From<S::Error>,
240245
D: ndarray::Dimension,
241246
{
242247
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");
243248

244-
let selection = selection.into();
249+
let selection = selection.try_into()?;
245250
let obj_space = self.obj.space()?;
246251

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

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

348354
impl ObjectClass for Container {
@@ -467,7 +473,8 @@ impl Container {
467473
pub fn read_slice_1d<T, S>(&self, selection: S) -> Result<Array1<T>>
468474
where
469475
T: H5Type,
470-
S: Into<Selection>,
476+
S: TryInto<Selection>,
477+
Error: From<S::Error>,
471478
{
472479
self.as_reader().read_slice_1d(selection)
473480
}
@@ -484,7 +491,8 @@ impl Container {
484491
pub fn read_slice_2d<T, S>(&self, selection: S) -> Result<Array2<T>>
485492
where
486493
T: H5Type,
487-
S: Into<Selection>,
494+
S: TryInto<Selection>,
495+
Error: From<S::Error>,
488496
{
489497
self.as_reader().read_slice_2d(selection)
490498
}
@@ -502,7 +510,8 @@ impl Container {
502510
pub fn read_slice<T, S, D>(&self, selection: S) -> Result<Array<T, D>>
503511
where
504512
T: H5Type,
505-
S: Into<Selection>,
513+
S: TryInto<Selection>,
514+
Error: From<S::Error>,
506515
D: ndarray::Dimension,
507516
{
508517
self.as_reader().read_slice(selection)
@@ -548,7 +557,8 @@ impl Container {
548557
where
549558
A: Into<ArrayView<'b, T, D>>,
550559
T: H5Type,
551-
S: Into<Selection>,
560+
S: TryInto<Selection>,
561+
Error: From<S::Error>,
552562
D: ndarray::Dimension,
553563
{
554564
self.as_writer().write_slice(arr, selection)

0 commit comments

Comments
 (0)