@@ -78,7 +78,7 @@ pub struct NewAxis;
7878/// A slice (range with step), an index, or a new axis token.
7979///
8080/// 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>`.
8282///
8383/// ## Examples
8484///
@@ -324,6 +324,24 @@ pub unsafe trait SliceArg<D: Dimension>: AsRef<[AxisSliceInfo]> {
324324 private_decl ! { }
325325}
326326
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+
327345macro_rules! impl_slicearg_samedim {
328346 ( $in_dim: ty) => {
329347 unsafe impl <T , Dout > SliceArg <$in_dim> for SliceInfo <T , $in_dim, Dout >
@@ -388,7 +406,7 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
388406
389407/// Represents all of the necessary information to perform a slice.
390408///
391- /// The type `T` is typically `[AxisSliceInfo; n]`, `[AxisSliceInfo]`, or
409+ /// The type `T` is typically `[AxisSliceInfo; n]`, `& [AxisSliceInfo]`, or
392410/// `Vec<AxisSliceInfo>`. The type `Din` is the dimension of the array to be
393411/// sliced, and `Dout` is the output dimension after calling [`.slice()`]. Note
394412/// that if `Din` is a fixed dimension type (`Ix0`, `Ix1`, `Ix2`, etc.), the
@@ -397,14 +415,13 @@ unsafe impl SliceArg<IxDyn> for [AxisSliceInfo] {
397415///
398416/// [`.slice()`]: struct.ArrayBase.html#method.slice
399417#[ derive( Debug ) ]
400- #[ repr( transparent) ]
401- pub struct SliceInfo < T : ?Sized , Din : Dimension , Dout : Dimension > {
418+ pub struct SliceInfo < T , Din : Dimension , Dout : Dimension > {
402419 in_dim : PhantomData < Din > ,
403420 out_dim : PhantomData < Dout > ,
404421 indices : T ,
405422}
406423
407- impl < T : ? Sized , Din , Dout > Deref for SliceInfo < T , Din , Dout >
424+ impl < T , Din , Dout > Deref for SliceInfo < T , Din , Dout >
408425where
409426 Din : Dimension ,
410427 Dout : Dimension ,
@@ -464,14 +481,7 @@ where
464481 indices,
465482 }
466483 }
467- }
468484
469- impl < T , Din , Dout > SliceInfo < T , Din , Dout >
470- where
471- T : AsRef < [ AxisSliceInfo ] > ,
472- Din : Dimension ,
473- Dout : Dimension ,
474- {
475485 /// Returns a new `SliceInfo` instance.
476486 ///
477487 /// Errors if `Din` or `Dout` is not consistent with `indices`.
@@ -490,14 +500,7 @@ where
490500 indices,
491501 } )
492502 }
493- }
494503
495- impl < T : ?Sized , Din , Dout > SliceInfo < T , Din , Dout >
496- where
497- T : AsRef < [ AxisSliceInfo ] > ,
498- Din : Dimension ,
499- Dout : Dimension ,
500- {
501504 /// Returns the number of dimensions of the input array for
502505 /// [`.slice()`](struct.ArrayBase.html#method.slice).
503506 ///
@@ -528,7 +531,7 @@ where
528531 }
529532}
530533
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 >
532535where
533536 Din : Dimension ,
534537 Dout : Dimension ,
@@ -537,16 +540,11 @@ where
537540
538541 fn try_from (
539542 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 > {
542544 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)
550548 }
551549 }
552550}
@@ -612,20 +610,18 @@ where
612610 }
613611}
614612
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 >
616615where
617616 T : AsRef < [ AxisSliceInfo ] > ,
618617 Din : Dimension ,
619618 Dout : Dimension ,
620619{
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 ( ) ,
629625 }
630626 }
631627}
@@ -703,9 +699,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1);
703699///
704700/// `s![]` takes a list of ranges/slices/indices/new-axes, separated by comma,
705701/// 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.
709703///
710704/// Each range/slice/index uses signed indices, where a negative value is
711705/// counted from the end of the axis. Step sizes are also signed and may be
@@ -889,9 +883,7 @@ macro_rules! s(
889883 <$crate:: AxisSliceInfo as :: std:: convert:: From <_>>:: from( $r) . step_by( $s as isize )
890884 } ;
891885 ( $( $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
895887 :: std:: marker:: PhantomData :: <$crate:: Ix0 >,
896888 :: std:: marker:: PhantomData :: <$crate:: Ix0 >,
897889 [ ]
@@ -933,7 +925,7 @@ where
933925 private_impl ! { }
934926}
935927
936- impl < ' a , A , D , I0 > MultiSliceArg < ' a , A , D > for ( & I0 , )
928+ impl < ' a , A , D , I0 > MultiSliceArg < ' a , A , D > for ( I0 , )
937929where
938930 A : ' a ,
939931 D : Dimension ,
@@ -942,7 +934,7 @@ where
942934 type Output = ( ArrayViewMut < ' a , A , I0 :: OutDim > , ) ;
943935
944936 fn multi_slice_move ( & self , view : ArrayViewMut < ' a , A , D > ) -> Self :: Output {
945- ( view. slice_move ( self . 0 ) , )
937+ ( view. slice_move ( & self . 0 ) , )
946938 }
947939
948940 private_impl ! { }
@@ -953,7 +945,7 @@ macro_rules! impl_multislice_tuple {
953945 impl_multislice_tuple!( @def_impl ( $( $but_last, ) * $last, ) , [ $( $but_last) * ] $last) ;
954946 } ;
955947 ( @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, ) * )
957949 where
958950 A : ' a,
959951 D : Dimension ,
@@ -963,7 +955,7 @@ macro_rules! impl_multislice_tuple {
963955
964956 fn multi_slice_move( & self , view: ArrayViewMut <' a, A , D >) -> Self :: Output {
965957 #[ allow( non_snake_case) ]
966- let & ( $( $all, ) * ) = self ;
958+ let ( $( $all, ) * ) = self ;
967959
968960 let shape = view. raw_dim( ) ;
969961 assert!( !impl_multislice_tuple!( @intersects_self & shape, ( $( $all, ) * ) ) ) ;
0 commit comments