Skip to content

Commit 3d567d6

Browse files
committed
use trait object to pass slice in (read|write)_slice* methods -- avoids extra type parameter
1 parent 1c7d7eb commit 3d567d6

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

hdf5-rs/src/hl/container.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ impl<'a> Reader<'a> {
6060
/// the slice, after singleton dimensions are dropped.
6161
/// Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
6262
/// a multidimensional slice.
63-
pub fn read_slice<T, S, D>(&self, slice: &SliceInfo<S, D>) -> Result<Array<T, D>>
63+
pub fn read_slice<T, D>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array<T, D>>
6464
where
6565
T: H5Type,
66-
S: AsRef<[SliceOrIndex]>,
6766
D: ndarray::Dimension,
6867
{
6968
ensure!(!self.obj.is_attr(), "slicing cannot be used on attribute datasets");
@@ -163,10 +162,9 @@ impl<'a> Reader<'a> {
163162
/// Reads the given `slice` of the dataset into a 1-dimensional array.
164163
///
165164
/// The dataset must be 1-dimensional.
166-
pub fn read_slice_1d<T, S>(&self, slice: &SliceInfo<S, Ix1>) -> Result<Array1<T>>
165+
pub fn read_slice_1d<T>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array1<T>>
167166
where
168167
T: H5Type,
169-
S: AsRef<[SliceOrIndex]>,
170168
{
171169
self.read_slice(slice)
172170
}
@@ -181,10 +179,9 @@ impl<'a> Reader<'a> {
181179
/// Reads the given `slice` of the dataset into a 2-dimensional array.
182180
///
183181
/// The dataset must be 2-dimensional.
184-
pub fn read_slice_2d<T, S>(&self, slice: &SliceInfo<S, Ix2>) -> Result<Array2<T>>
182+
pub fn read_slice_2d<T>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array2<T>>
185183
where
186184
T: H5Type,
187-
S: AsRef<[SliceOrIndex]>,
188185
{
189186
self.read_slice(slice)
190187
}
@@ -253,11 +250,10 @@ impl<'a> Writer<'a> {
253250
/// If the array has a fixed number of dimensions, it must match the dimensionality of
254251
/// dataset. Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
255252
/// a multidimensional slice.
256-
pub fn write_slice<'b, A, T, S, D>(&self, arr: A, slice: &SliceInfo<S, D>) -> Result<()>
253+
pub fn write_slice<'b, A, T, D>(&self, arr: A, slice: &AsRef<[SliceOrIndex]>) -> Result<()>
257254
where
258255
A: Into<ArrayView<'b, T, D>>,
259256
T: H5Type,
260-
S: AsRef<[SliceOrIndex]>,
261257
D: ndarray::Dimension,
262258
{
263259
ensure!(!self.obj.is_attr(), "slicing cannot be used on attribute datasets");
@@ -500,10 +496,9 @@ impl Container {
500496
/// Reads the given `slice` of the dataset into a 1-dimensional array.
501497
///
502498
/// The dataset must be 1-dimensional.
503-
pub fn read_slice_1d<T, S>(&self, slice: &SliceInfo<S, Ix1>) -> Result<Array1<T>>
499+
pub fn read_slice_1d<T>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array1<T>>
504500
where
505-
T: H5Type,
506-
S: AsRef<[SliceOrIndex]>,
501+
T: H5Type
507502
{
508503
self.as_reader().read_slice_1d(slice)
509504
}
@@ -518,10 +513,9 @@ impl Container {
518513
/// Reads the given `slice` of the dataset into a 2-dimensional array.
519514
///
520515
/// The dataset must be 2-dimensional.
521-
pub fn read_slice_2d<T, S>(&self, slice: &SliceInfo<S, Ix2>) -> Result<Array2<T>>
516+
pub fn read_slice_2d<T>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array2<T>>
522517
where
523-
T: H5Type,
524-
S: AsRef<[SliceOrIndex]>,
518+
T: H5Type
525519
{
526520
self.as_reader().read_slice_2d(slice)
527521
}
@@ -536,10 +530,9 @@ impl Container {
536530
/// the slice, after singleton dimensions are dropped.
537531
/// Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
538532
/// a multidimensional slice.
539-
pub fn read_slice<T, S, D>(&self, slice: &SliceInfo<S, D>) -> Result<Array<T, D>>
533+
pub fn read_slice<T, D>(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Array<T, D>>
540534
where
541535
T: H5Type,
542-
S: AsRef<[SliceOrIndex]>,
543536
D: ndarray::Dimension,
544537
{
545538
self.as_reader().read_slice(slice)
@@ -581,11 +574,10 @@ impl Container {
581574
/// If the array has a fixed number of dimensions, it must match the dimensionality of
582575
/// dataset. Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
583576
/// a multidimensional slice.
584-
pub fn write_slice<'b, A, T, S, D>(&self, arr: A, slice: &SliceInfo<S, D>) -> Result<()>
577+
pub fn write_slice<'b, A, T, D>(&self, arr: A, slice: &AsRef<[SliceOrIndex]>) -> Result<()>
585578
where
586579
A: Into<ArrayView<'b, T, D>>,
587580
T: H5Type,
588-
S: AsRef<[SliceOrIndex]>,
589581
D: ndarray::Dimension,
590582
{
591583
self.as_writer().write_slice(arr, slice)

hdf5-rs/src/hl/space.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ impl Dataspace {
5656
/// Select a slice (known as a 'hyperslab' in HDF5 terminology) of the Dataspace.
5757
/// Returns the shape of array that is capable of holding the resulting slice.
5858
/// Useful when you want to read a subset of a dataset.
59-
pub fn select_slice<T, D>(&self, slice: &SliceInfo<T, D>) -> Result<Vec<Ix>>
60-
where
61-
T: AsRef<[SliceOrIndex]>,
62-
D: ndarray::Dimension,
59+
pub fn select_slice(&self, slice: &AsRef<[SliceOrIndex]>) -> Result<Vec<Ix>>
6360
{
6461
let shape = self.dims();
6562
let ss: &[SliceOrIndex] = slice.as_ref();

0 commit comments

Comments
 (0)