@@ -692,44 +692,45 @@ where
692
692
}
693
693
}
694
694
695
- macro_rules! arith_scalar_func {
696
- ( $rust_type : ty , $ op_name: ident, $fn_name: ident) => {
695
+ macro_rules! arith_rhs_scalar_func {
696
+ ( $op_name: ident, $fn_name: ident) => {
697
697
// Implement (&Array<T> op_name rust_type)
698
- impl <' f, T > $op_name<$rust_type > for & ' f Array <T >
698
+ impl <' f, T , U > $op_name<U > for & ' f Array <T >
699
699
where
700
- T : HasAfEnum + ImplicitPromote <$rust_type>,
701
- $rust_type: HasAfEnum + ImplicitPromote <T >,
702
- <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
700
+ T : HasAfEnum + ImplicitPromote <U >,
701
+ U : HasAfEnum + ImplicitPromote <T > + Clone + ConstGenerator <OutType = U >,
703
702
{
704
- type Output = Array <<T as ImplicitPromote <$rust_type >>:: Output >;
703
+ type Output = Array <<T as ImplicitPromote <U >>:: Output >;
705
704
706
- fn $fn_name( self , rhs: $rust_type ) -> Self :: Output {
705
+ fn $fn_name( self , rhs: U ) -> Self :: Output {
707
706
let temp = rhs. clone( ) ;
708
707
$fn_name( self , & temp, false )
709
708
}
710
709
}
711
710
712
711
// Implement (Array<T> op_name rust_type)
713
- impl <T : HasAfEnum > $op_name<$rust_type > for Array <T >
712
+ impl <T , U > $op_name<U > for Array <T >
714
713
where
715
- T : HasAfEnum + ImplicitPromote <$rust_type>,
716
- $rust_type: HasAfEnum + ImplicitPromote <T >,
717
- <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
714
+ T : HasAfEnum + ImplicitPromote <U >,
715
+ U : HasAfEnum + ImplicitPromote <T > + Clone + ConstGenerator <OutType = U >,
718
716
{
719
- type Output = Array <<T as ImplicitPromote <$rust_type >>:: Output >;
717
+ type Output = Array <<T as ImplicitPromote <U >>:: Output >;
720
718
721
- fn $fn_name( self , rhs: $rust_type ) -> Self :: Output {
719
+ fn $fn_name( self , rhs: U ) -> Self :: Output {
722
720
let temp = rhs. clone( ) ;
723
721
$fn_name( & self , & temp, false )
724
722
}
725
723
}
724
+ } ;
725
+ }
726
726
727
+ macro_rules! arith_lhs_scalar_func {
728
+ ( $rust_type: ty, $op_name: ident, $fn_name: ident) => {
727
729
// Implement (rust_type op_name &Array<T>)
728
730
impl <' f, T > $op_name<& ' f Array <T >> for $rust_type
729
731
where
730
732
T : HasAfEnum + ImplicitPromote <$rust_type>,
731
733
$rust_type: HasAfEnum + ImplicitPromote <T >,
732
- <$rust_type as ImplicitPromote <T >>:: Output : HasAfEnum ,
733
734
{
734
735
type Output = Array <<$rust_type as ImplicitPromote <T >>:: Output >;
735
736
@@ -743,7 +744,6 @@ macro_rules! arith_scalar_func {
743
744
where
744
745
T : HasAfEnum + ImplicitPromote <$rust_type>,
745
746
$rust_type: HasAfEnum + ImplicitPromote <T >,
746
- <$rust_type as ImplicitPromote <T >>:: Output : HasAfEnum ,
747
747
{
748
748
type Output = Array <<$rust_type as ImplicitPromote <T >>:: Output >;
749
749
@@ -754,12 +754,17 @@ macro_rules! arith_scalar_func {
754
754
} ;
755
755
}
756
756
757
+ arith_rhs_scalar_func ! ( Add , add) ;
758
+ arith_rhs_scalar_func ! ( Sub , sub) ;
759
+ arith_rhs_scalar_func ! ( Mul , mul) ;
760
+ arith_rhs_scalar_func ! ( Div , div) ;
761
+
757
762
macro_rules! arith_scalar_spec {
758
763
( $ty_name: ty) => {
759
- arith_scalar_func !( $ty_name, Add , add) ;
760
- arith_scalar_func !( $ty_name, Sub , sub) ;
761
- arith_scalar_func !( $ty_name, Mul , mul) ;
762
- arith_scalar_func !( $ty_name, Div , div) ;
764
+ arith_lhs_scalar_func !( $ty_name, Add , add) ;
765
+ arith_lhs_scalar_func !( $ty_name, Sub , sub) ;
766
+ arith_lhs_scalar_func !( $ty_name, Mul , mul) ;
767
+ arith_lhs_scalar_func !( $ty_name, Div , div) ;
763
768
} ;
764
769
}
765
770
0 commit comments