@@ -406,7 +406,7 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
406
406
407
407
/// Represents all of the necessary information to perform a slice.
408
408
///
409
- /// The type `T` is typically `[AxisSliceInfo; n]`, `[AxisSliceInfo]`, or
409
+ /// The type `T` is typically `[AxisSliceInfo; n]`, `& [AxisSliceInfo]`, or
410
410
/// `Vec<AxisSliceInfo>`. The type `Din` is the dimension of the array to be
411
411
/// sliced, and `Dout` is the output dimension after calling [`.slice()`]. Note
412
412
/// that if `Din` is a fixed dimension type (`Ix0`, `Ix1`, `Ix2`, etc.), the
@@ -415,14 +415,13 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
415
415
///
416
416
/// [`.slice()`]: struct.ArrayBase.html#method.slice
417
417
#[ derive( Debug ) ]
418
- #[ repr( transparent) ]
419
- pub struct SliceInfo < T : ?Sized , Din : Dimension , Dout : Dimension > {
418
+ pub struct SliceInfo < T , Din : Dimension , Dout : Dimension > {
420
419
in_dim : PhantomData < Din > ,
421
420
out_dim : PhantomData < Dout > ,
422
421
indices : T ,
423
422
}
424
423
425
- impl < T : ? Sized , Din , Dout > Deref for SliceInfo < T , Din , Dout >
424
+ impl < T , Din , Dout > Deref for SliceInfo < T , Din , Dout >
426
425
where
427
426
Din : Dimension ,
428
427
Dout : Dimension ,
@@ -482,14 +481,7 @@ where
482
481
indices,
483
482
}
484
483
}
485
- }
486
484
487
- impl < T , Din , Dout > SliceInfo < T , Din , Dout >
488
- where
489
- T : AsRef < [ AxisSliceInfo ] > ,
490
- Din : Dimension ,
491
- Dout : Dimension ,
492
- {
493
485
/// Returns a new `SliceInfo` instance.
494
486
///
495
487
/// Errors if `Din` or `Dout` is not consistent with `indices`.
@@ -508,14 +500,7 @@ where
508
500
indices,
509
501
} )
510
502
}
511
- }
512
503
513
- impl < T : ?Sized , Din , Dout > SliceInfo < T , Din , Dout >
514
- where
515
- T : AsRef < [ AxisSliceInfo ] > ,
516
- Din : Dimension ,
517
- Dout : Dimension ,
518
- {
519
504
/// Returns the number of dimensions of the input array for
520
505
/// [`.slice()`](struct.ArrayBase.html#method.slice).
521
506
///
@@ -546,7 +531,7 @@ where
546
531
}
547
532
}
548
533
549
- impl < ' a , Din , Dout > TryFrom < & ' a [ AxisSliceInfo ] > for & ' a SliceInfo < [ AxisSliceInfo ] , Din , Dout >
534
+ impl < ' a , Din , Dout > TryFrom < & ' a [ AxisSliceInfo ] > for SliceInfo < & ' a [ AxisSliceInfo ] , Din , Dout >
550
535
where
551
536
Din : Dimension ,
552
537
Dout : Dimension ,
@@ -555,16 +540,11 @@ where
555
540
556
541
fn try_from (
557
542
indices : & ' a [ AxisSliceInfo ] ,
558
- ) -> Result < & ' a SliceInfo < [ AxisSliceInfo ] , Din , Dout > , ShapeError > {
559
- check_dims_for_sliceinfo :: < Din , Dout > ( indices) ?;
543
+ ) -> Result < SliceInfo < & ' a [ AxisSliceInfo ] , Din , Dout > , ShapeError > {
560
544
unsafe {
561
- // This is okay because we've already checked the correctness of
562
- // `Din` and `Dout`, and the only non-zero-sized member of
563
- // `SliceInfo` is `indices`, so `&SliceInfo<[AxisSliceInfo], Din,
564
- // Dout>` should have the same bitwise representation as
565
- // `&[AxisSliceInfo]`.
566
- Ok ( & * ( indices as * const [ AxisSliceInfo ]
567
- as * const SliceInfo < [ AxisSliceInfo ] , Din , Dout > ) )
545
+ // This is okay because `&[AxisSliceInfo]` always returns the same
546
+ // value for `.as_ref()`.
547
+ Self :: new ( indices)
568
548
}
569
549
}
570
550
}
@@ -630,20 +610,18 @@ where
630
610
}
631
611
}
632
612
633
- impl < T , Din , Dout > AsRef < SliceInfo < [ AxisSliceInfo ] , Din , Dout > > for SliceInfo < T , Din , Dout >
613
+ impl < ' a , T , Din , Dout > From < & ' a SliceInfo < T , Din , Dout > >
614
+ for SliceInfo < & ' a [ AxisSliceInfo ] , Din , Dout >
634
615
where
635
616
T : AsRef < [ AxisSliceInfo ] > ,
636
617
Din : Dimension ,
637
618
Dout : Dimension ,
638
619
{
639
- fn as_ref ( & self ) -> & SliceInfo < [ AxisSliceInfo ] , Din , Dout > {
640
- unsafe {
641
- // This is okay because the only non-zero-sized member of
642
- // `SliceInfo` is `indices`, so `&SliceInfo<[AxisSliceInfo], Din, Dout>`
643
- // should have the same bitwise representation as
644
- // `&[AxisSliceInfo]`.
645
- & * ( self . indices . as_ref ( ) as * const [ AxisSliceInfo ]
646
- as * const SliceInfo < [ AxisSliceInfo ] , Din , Dout > )
620
+ fn from ( info : & ' a SliceInfo < T , Din , Dout > ) -> SliceInfo < & ' a [ AxisSliceInfo ] , Din , Dout > {
621
+ SliceInfo {
622
+ in_dim : info. in_dim ,
623
+ out_dim : info. out_dim ,
624
+ indices : info. indices . as_ref ( ) ,
647
625
}
648
626
}
649
627
}
0 commit comments