@@ -78,7 +78,7 @@ pub struct NewAxis;
78
78
/// A slice (range with step), an index, or a new axis token.
79
79
///
80
80
/// See also the [`s![]`](macro.s!.html) macro for a convenient way to create a
81
- /// `& SliceInfo<[AxisSliceInfo; n], Din, Dout>`.
81
+ /// `SliceInfo<[AxisSliceInfo; n], Din, Dout>`.
82
82
///
83
83
/// ## Examples
84
84
///
@@ -324,6 +324,24 @@ pub unsafe trait SliceArg<D: Dimension>: AsRef<[AxisSliceInfo]> {
324
324
private_decl ! { }
325
325
}
326
326
327
+ unsafe impl < T , D > SliceArg < D > for & T
328
+ where
329
+ T : SliceArg < D > + ?Sized ,
330
+ D : Dimension ,
331
+ {
332
+ type OutDim = T :: OutDim ;
333
+
334
+ fn in_ndim ( & self ) -> usize {
335
+ T :: in_ndim ( self )
336
+ }
337
+
338
+ fn out_ndim ( & self ) -> usize {
339
+ T :: out_ndim ( self )
340
+ }
341
+
342
+ private_impl ! { }
343
+ }
344
+
327
345
macro_rules! impl_slicearg_samedim {
328
346
( $in_dim: ty) => {
329
347
unsafe impl <T , Dout > SliceArg <$in_dim> for SliceInfo <T , $in_dim, Dout >
@@ -388,7 +406,7 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
388
406
389
407
/// Represents all of the necessary information to perform a slice.
390
408
///
391
- /// The type `T` is typically `[AxisSliceInfo; n]`, `[AxisSliceInfo]`, or
409
+ /// The type `T` is typically `[AxisSliceInfo; n]`, `& [AxisSliceInfo]`, or
392
410
/// `Vec<AxisSliceInfo>`. The type `Din` is the dimension of the array to be
393
411
/// sliced, and `Dout` is the output dimension after calling [`.slice()`]. Note
394
412
/// that if `Din` is a fixed dimension type (`Ix0`, `Ix1`, `Ix2`, etc.), the
@@ -397,14 +415,13 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
397
415
///
398
416
/// [`.slice()`]: struct.ArrayBase.html#method.slice
399
417
#[ derive( Debug ) ]
400
- #[ repr( transparent) ]
401
- pub struct SliceInfo < T : ?Sized , Din : Dimension , Dout : Dimension > {
418
+ pub struct SliceInfo < T , Din : Dimension , Dout : Dimension > {
402
419
in_dim : PhantomData < Din > ,
403
420
out_dim : PhantomData < Dout > ,
404
421
indices : T ,
405
422
}
406
423
407
- impl < T : ? Sized , Din , Dout > Deref for SliceInfo < T , Din , Dout >
424
+ impl < T , Din , Dout > Deref for SliceInfo < T , Din , Dout >
408
425
where
409
426
Din : Dimension ,
410
427
Dout : Dimension ,
@@ -464,14 +481,7 @@ where
464
481
indices,
465
482
}
466
483
}
467
- }
468
484
469
- impl < T , Din , Dout > SliceInfo < T , Din , Dout >
470
- where
471
- T : AsRef < [ AxisSliceInfo ] > ,
472
- Din : Dimension ,
473
- Dout : Dimension ,
474
- {
475
485
/// Returns a new `SliceInfo` instance.
476
486
///
477
487
/// Errors if `Din` or `Dout` is not consistent with `indices`.
@@ -490,14 +500,7 @@ where
490
500
indices,
491
501
} )
492
502
}
493
- }
494
503
495
- impl < T : ?Sized , Din , Dout > SliceInfo < T , Din , Dout >
496
- where
497
- T : AsRef < [ AxisSliceInfo ] > ,
498
- Din : Dimension ,
499
- Dout : Dimension ,
500
- {
501
504
/// Returns the number of dimensions of the input array for
502
505
/// [`.slice()`](struct.ArrayBase.html#method.slice).
503
506
///
@@ -528,7 +531,7 @@ where
528
531
}
529
532
}
530
533
531
- 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 >
532
535
where
533
536
Din : Dimension ,
534
537
Dout : Dimension ,
@@ -537,16 +540,11 @@ where
537
540
538
541
fn try_from (
539
542
indices : & ' a [ AxisSliceInfo ] ,
540
- ) -> Result < & ' a SliceInfo < [ AxisSliceInfo ] , Din , Dout > , ShapeError > {
541
- check_dims_for_sliceinfo :: < Din , Dout > ( indices) ?;
543
+ ) -> Result < SliceInfo < & ' a [ AxisSliceInfo ] , Din , Dout > , ShapeError > {
542
544
unsafe {
543
- // This is okay because we've already checked the correctness of
544
- // `Din` and `Dout`, and the only non-zero-sized member of
545
- // `SliceInfo` is `indices`, so `&SliceInfo<[AxisSliceInfo], Din,
546
- // Dout>` should have the same bitwise representation as
547
- // `&[AxisSliceInfo]`.
548
- Ok ( & * ( indices as * const [ AxisSliceInfo ]
549
- 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)
550
548
}
551
549
}
552
550
}
@@ -612,20 +610,18 @@ where
612
610
}
613
611
}
614
612
615
- 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 >
616
615
where
617
616
T : AsRef < [ AxisSliceInfo ] > ,
618
617
Din : Dimension ,
619
618
Dout : Dimension ,
620
619
{
621
- fn as_ref ( & self ) -> & SliceInfo < [ AxisSliceInfo ] , Din , Dout > {
622
- unsafe {
623
- // This is okay because the only non-zero-sized member of
624
- // `SliceInfo` is `indices`, so `&SliceInfo<[AxisSliceInfo], Din, Dout>`
625
- // should have the same bitwise representation as
626
- // `&[AxisSliceInfo]`.
627
- & * ( self . indices . as_ref ( ) as * const [ AxisSliceInfo ]
628
- 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 ( ) ,
629
625
}
630
626
}
631
627
}
@@ -703,9 +699,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1);
703
699
///
704
700
/// `s![]` takes a list of ranges/slices/indices/new-axes, separated by comma,
705
701
/// with optional step sizes that are separated from the range by a semicolon.
706
- /// It is converted into a [`&SliceInfo`] instance.
707
- ///
708
- /// [`&SliceInfo`]: struct.SliceInfo.html
702
+ /// It is converted into a [`SliceInfo`] instance.
709
703
///
710
704
/// Each range/slice/index uses signed indices, where a negative value is
711
705
/// counted from the end of the axis. Step sizes are also signed and may be
@@ -889,9 +883,7 @@ macro_rules! s(
889
883
<$crate:: AxisSliceInfo as :: std:: convert:: From <_>>:: from( $r) . step_by( $s as isize )
890
884
} ;
891
885
( $( $t: tt) * ) => {
892
- // The extra `*&` is a workaround for this compiler bug:
893
- // https://github.com/rust-lang/rust/issues/23014
894
- & * & $crate:: s![ @parse
886
+ $crate:: s![ @parse
895
887
:: std:: marker:: PhantomData :: <$crate:: Ix0 >,
896
888
:: std:: marker:: PhantomData :: <$crate:: Ix0 >,
897
889
[ ]
@@ -933,7 +925,7 @@ where
933
925
private_impl ! { }
934
926
}
935
927
936
- impl < ' a , A , D , I0 > MultiSliceArg < ' a , A , D > for ( & I0 , )
928
+ impl < ' a , A , D , I0 > MultiSliceArg < ' a , A , D > for ( I0 , )
937
929
where
938
930
A : ' a ,
939
931
D : Dimension ,
@@ -942,7 +934,7 @@ where
942
934
type Output = ( ArrayViewMut < ' a , A , I0 :: OutDim > , ) ;
943
935
944
936
fn multi_slice_move ( & self , view : ArrayViewMut < ' a , A , D > ) -> Self :: Output {
945
- ( view. slice_move ( self . 0 ) , )
937
+ ( view. slice_move ( & self . 0 ) , )
946
938
}
947
939
948
940
private_impl ! { }
@@ -953,7 +945,7 @@ macro_rules! impl_multislice_tuple {
953
945
impl_multislice_tuple!( @def_impl ( $( $but_last, ) * $last, ) , [ $( $but_last) * ] $last) ;
954
946
} ;
955
947
( @def_impl ( $( $all: ident, ) * ) , [ $( $but_last: ident) * ] $last: ident) => {
956
- impl <' a, A , D , $( $all, ) * > MultiSliceArg <' a, A , D > for ( $( & $all, ) * )
948
+ impl <' a, A , D , $( $all, ) * > MultiSliceArg <' a, A , D > for ( $( $all, ) * )
957
949
where
958
950
A : ' a,
959
951
D : Dimension ,
@@ -963,7 +955,7 @@ macro_rules! impl_multislice_tuple {
963
955
964
956
fn multi_slice_move( & self , view: ArrayViewMut <' a, A , D >) -> Self :: Output {
965
957
#[ allow( non_snake_case) ]
966
- let & ( $( $all, ) * ) = self ;
958
+ let ( $( $all, ) * ) = self ;
967
959
968
960
let shape = view. raw_dim( ) ;
969
961
assert!( !impl_multislice_tuple!( @intersects_self & shape, ( $( $all, ) * ) ) ) ;
0 commit comments