Skip to content

Commit 2df478f

Browse files
committed
Rework SliceOrIndex to fit with valid selections
1 parent 31af591 commit 2df478f

File tree

3 files changed

+44
-180
lines changed

3 files changed

+44
-180
lines changed

src/hl/container.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,12 @@ impl<'a> Reader<'a> {
6969
where
7070
T: H5Type,
7171
S: TryInto<Selection>,
72+
Error: From<S::Error>,
7273
D: ndarray::Dimension,
7374
{
7475
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");
7576

76-
let selection = if let Ok(selection) = selection.try_into() {
77-
selection
78-
} else {
79-
fail!("Selection is not valid for hdf5")
80-
};
77+
let selection = selection.try_into()?;
8178
let obj_space = self.obj.space()?;
8279

8380
let out_shape = selection.out_shape(&obj_space.shape())?;
@@ -151,6 +148,7 @@ impl<'a> Reader<'a> {
151148
where
152149
T: H5Type,
153150
S: TryInto<Selection>,
151+
Error: From<S::Error>,
154152
{
155153
self.read_slice(selection)
156154
}
@@ -168,6 +166,7 @@ impl<'a> Reader<'a> {
168166
where
169167
T: H5Type,
170168
S: TryInto<Selection>,
169+
Error: From<S::Error>,
171170
{
172171
self.read_slice(selection)
173172
}
@@ -240,15 +239,12 @@ impl<'a> Writer<'a> {
240239
A: Into<ArrayView<'b, T, D>>,
241240
T: H5Type,
242241
S: TryInto<Selection>,
242+
Error: From<S::Error>,
243243
D: ndarray::Dimension,
244244
{
245245
ensure!(!self.obj.is_attr(), "Slicing cannot be used on attribute datasets");
246246

247-
let selection = if let Ok(selection) = selection.try_into() {
248-
selection
249-
} else {
250-
fail!("Selection is not valid for hdf5")
251-
};
247+
let selection = selection.try_into()?;
252248
let obj_space = self.obj.space()?;
253249

254250
let out_shape = selection.out_shape(&obj_space.shape())?;
@@ -475,6 +471,7 @@ impl Container {
475471
where
476472
T: H5Type,
477473
S: TryInto<Selection>,
474+
Error: From<S::Error>,
478475
{
479476
self.as_reader().read_slice_1d(selection)
480477
}
@@ -492,6 +489,7 @@ impl Container {
492489
where
493490
T: H5Type,
494491
S: TryInto<Selection>,
492+
Error: From<S::Error>,
495493
{
496494
self.as_reader().read_slice_2d(selection)
497495
}
@@ -510,6 +508,7 @@ impl Container {
510508
where
511509
T: H5Type,
512510
S: TryInto<Selection>,
511+
Error: From<S::Error>,
513512
D: ndarray::Dimension,
514513
{
515514
self.as_reader().read_slice(selection)
@@ -556,6 +555,7 @@ impl Container {
556555
A: Into<ArrayView<'b, T, D>>,
557556
T: H5Type,
558557
S: TryInto<Selection>,
558+
Error: From<S::Error>,
559559
D: ndarray::Dimension,
560560
{
561561
self.as_writer().write_slice(arr, selection)

0 commit comments

Comments
 (0)