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,13 @@ 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 > ,
72
+ Error : From < S :: Error > ,
71
73
D : ndarray:: Dimension ,
72
74
{
73
75
ensure ! ( !self . obj. is_attr( ) , "Slicing cannot be used on attribute datasets" ) ;
74
76
75
- let selection = selection. into ( ) ;
77
+ let selection = selection. try_into ( ) ? ;
76
78
let obj_space = self . obj . space ( ) ?;
77
79
78
80
let out_shape = selection. out_shape ( & obj_space. shape ( ) ) ?;
@@ -147,7 +149,8 @@ impl<'a> Reader<'a> {
147
149
pub fn read_slice_1d < T , S > ( & self , selection : S ) -> Result < Array1 < T > >
148
150
where
149
151
T : H5Type ,
150
- S : Into < Selection > ,
152
+ S : TryInto < Selection > ,
153
+ Error : From < S :: Error > ,
151
154
{
152
155
self . read_slice ( selection)
153
156
}
@@ -164,7 +167,8 @@ impl<'a> Reader<'a> {
164
167
pub fn read_slice_2d < T , S > ( & self , selection : S ) -> Result < Array2 < T > >
165
168
where
166
169
T : H5Type ,
167
- S : Into < Selection > ,
170
+ S : TryInto < Selection > ,
171
+ Error : From < S :: Error > ,
168
172
{
169
173
self . read_slice ( selection)
170
174
}
@@ -236,12 +240,13 @@ impl<'a> Writer<'a> {
236
240
where
237
241
A : Into < ArrayView < ' b , T , D > > ,
238
242
T : H5Type ,
239
- S : Into < Selection > ,
243
+ S : TryInto < Selection > ,
244
+ Error : From < S :: Error > ,
240
245
D : ndarray:: Dimension ,
241
246
{
242
247
ensure ! ( !self . obj. is_attr( ) , "Slicing cannot be used on attribute datasets" ) ;
243
248
244
- let selection = selection. into ( ) ;
249
+ let selection = selection. try_into ( ) ? ;
245
250
let obj_space = self . obj . space ( ) ?;
246
251
247
252
let out_shape = selection. out_shape ( & obj_space. shape ( ) ) ?;
@@ -343,6 +348,7 @@ impl<'a> Writer<'a> {
343
348
344
349
#[ repr( transparent) ]
345
350
#[ derive( Clone ) ]
351
+ /// An object which can be read or written to.
346
352
pub struct Container ( Handle ) ;
347
353
348
354
impl ObjectClass for Container {
@@ -467,7 +473,8 @@ impl Container {
467
473
pub fn read_slice_1d < T , S > ( & self , selection : S ) -> Result < Array1 < T > >
468
474
where
469
475
T : H5Type ,
470
- S : Into < Selection > ,
476
+ S : TryInto < Selection > ,
477
+ Error : From < S :: Error > ,
471
478
{
472
479
self . as_reader ( ) . read_slice_1d ( selection)
473
480
}
@@ -484,7 +491,8 @@ impl Container {
484
491
pub fn read_slice_2d < T , S > ( & self , selection : S ) -> Result < Array2 < T > >
485
492
where
486
493
T : H5Type ,
487
- S : Into < Selection > ,
494
+ S : TryInto < Selection > ,
495
+ Error : From < S :: Error > ,
488
496
{
489
497
self . as_reader ( ) . read_slice_2d ( selection)
490
498
}
@@ -502,7 +510,8 @@ impl Container {
502
510
pub fn read_slice < T , S , D > ( & self , selection : S ) -> Result < Array < T , D > >
503
511
where
504
512
T : H5Type ,
505
- S : Into < Selection > ,
513
+ S : TryInto < Selection > ,
514
+ Error : From < S :: Error > ,
506
515
D : ndarray:: Dimension ,
507
516
{
508
517
self . as_reader ( ) . read_slice ( selection)
@@ -548,7 +557,8 @@ impl Container {
548
557
where
549
558
A : Into < ArrayView < ' b , T , D > > ,
550
559
T : H5Type ,
551
- S : Into < Selection > ,
560
+ S : TryInto < Selection > ,
561
+ Error : From < S :: Error > ,
552
562
D : ndarray:: Dimension ,
553
563
{
554
564
self . as_writer ( ) . write_slice ( arr, selection)
0 commit comments