1
+ use std:: convert:: TryInto ;
1
2
use std:: fmt:: { self , Debug } ;
2
3
use std:: mem;
3
4
use std:: ops:: Deref ;
@@ -67,12 +68,16 @@ impl<'a> Reader<'a> {
67
68
pub fn read_slice < T , S , D > ( & self , selection : S ) -> Result < Array < T , D > >
68
69
where
69
70
T : H5Type ,
70
- S : Into < Selection > ,
71
+ S : TryInto < Selection > ,
71
72
D : ndarray:: Dimension ,
72
73
{
73
74
ensure ! ( !self . obj. is_attr( ) , "Slicing cannot be used on attribute datasets" ) ;
74
75
75
- let selection = selection. into ( ) ;
76
+ let selection = if let Ok ( selection) = selection. try_into ( ) {
77
+ selection
78
+ } else {
79
+ fail ! ( "Selection is not valid for hdf5" )
80
+ } ;
76
81
let obj_space = self . obj . space ( ) ?;
77
82
78
83
let out_shape = selection. out_shape ( & obj_space. shape ( ) ) ?;
@@ -145,7 +150,7 @@ impl<'a> Reader<'a> {
145
150
pub fn read_slice_1d < T , S > ( & self , selection : S ) -> Result < Array1 < T > >
146
151
where
147
152
T : H5Type ,
148
- S : Into < Selection > ,
153
+ S : TryInto < Selection > ,
149
154
{
150
155
self . read_slice ( selection)
151
156
}
@@ -162,7 +167,7 @@ impl<'a> Reader<'a> {
162
167
pub fn read_slice_2d < T , S > ( & self , selection : S ) -> Result < Array2 < T > >
163
168
where
164
169
T : H5Type ,
165
- S : Into < Selection > ,
170
+ S : TryInto < Selection > ,
166
171
{
167
172
self . read_slice ( selection)
168
173
}
@@ -234,12 +239,16 @@ impl<'a> Writer<'a> {
234
239
where
235
240
A : Into < ArrayView < ' b , T , D > > ,
236
241
T : H5Type ,
237
- S : Into < Selection > ,
242
+ S : TryInto < Selection > ,
238
243
D : ndarray:: Dimension ,
239
244
{
240
245
ensure ! ( !self . obj. is_attr( ) , "Slicing cannot be used on attribute datasets" ) ;
241
246
242
- let selection = selection. into ( ) ;
247
+ let selection = if let Ok ( selection) = selection. try_into ( ) {
248
+ selection
249
+ } else {
250
+ fail ! ( "Selection is not valid for hdf5" )
251
+ } ;
243
252
let obj_space = self . obj . space ( ) ?;
244
253
245
254
let out_shape = selection. out_shape ( & obj_space. shape ( ) ) ?;
@@ -465,7 +474,7 @@ impl Container {
465
474
pub fn read_slice_1d < T , S > ( & self , selection : S ) -> Result < Array1 < T > >
466
475
where
467
476
T : H5Type ,
468
- S : Into < Selection > ,
477
+ S : TryInto < Selection > ,
469
478
{
470
479
self . as_reader ( ) . read_slice_1d ( selection)
471
480
}
@@ -482,7 +491,7 @@ impl Container {
482
491
pub fn read_slice_2d < T , S > ( & self , selection : S ) -> Result < Array2 < T > >
483
492
where
484
493
T : H5Type ,
485
- S : Into < Selection > ,
494
+ S : TryInto < Selection > ,
486
495
{
487
496
self . as_reader ( ) . read_slice_2d ( selection)
488
497
}
@@ -500,7 +509,7 @@ impl Container {
500
509
pub fn read_slice < T , S , D > ( & self , selection : S ) -> Result < Array < T , D > >
501
510
where
502
511
T : H5Type ,
503
- S : Into < Selection > ,
512
+ S : TryInto < Selection > ,
504
513
D : ndarray:: Dimension ,
505
514
{
506
515
self . as_reader ( ) . read_slice ( selection)
@@ -546,7 +555,7 @@ impl Container {
546
555
where
547
556
A : Into < ArrayView < ' b , T , D > > ,
548
557
T : H5Type ,
549
- S : Into < Selection > ,
558
+ S : TryInto < Selection > ,
550
559
D : ndarray:: Dimension ,
551
560
{
552
561
self . as_writer ( ) . write_slice ( arr, selection)
0 commit comments