src/direct_product.rs

branch
dev
changeset 120
07e487685b29
parent 119
cc0c6a8d0933
child 121
fc7d923ff6e7
equal deleted inserted replaced
119:cc0c6a8d0933 120:07e487685b29
123 123
124 impl_binary!(Add, add); 124 impl_binary!(Add, add);
125 impl_binary!(Sub, sub); 125 impl_binary!(Sub, sub);
126 126
127 macro_rules! impl_scalar { 127 macro_rules! impl_scalar {
128 ($trait:ident, $fn:ident, $F:ty) => { 128 ($trait:ident, $fn:ident) => {
129 impl<A, B> $trait<$F> for Pair<A, B> 129 impl<A, B, F: Num> $trait<F> for Pair<A, B>
130 where 130 where
131 A: $trait<$F>, 131 A: $trait<F>,
132 B: $trait<$F>, 132 B: $trait<F>,
133 { 133 {
134 type Output = Pair<A::Output, B::Output>; 134 type Output = Pair<A::Output, B::Output>;
135 fn $fn(self, t: $F) -> Self::Output { 135 fn $fn(self, t: F) -> Self::Output {
136 let Pair(a, b) = self; 136 let Pair(a, b) = self;
137 Pair(a.$fn(t), b.$fn(t)) 137 Pair(a.$fn(t), b.$fn(t))
138 } 138 }
139 } 139 }
140 140
141 impl<'a, A, B> $trait<$F> for &'a Pair<A, B> 141 impl<'a, A, B, F: Num> $trait<F> for &'a Pair<A, B>
142 where 142 where
143 &'a A: $trait<$F>, 143 &'a A: $trait<F>,
144 &'a B: $trait<$F>, 144 &'a B: $trait<F>,
145 { 145 {
146 type Output = Pair<<&'a A as $trait<$F>>::Output, <&'a B as $trait<$F>>::Output>; 146 type Output = Pair<<&'a A as $trait<F>>::Output, <&'a B as $trait<F>>::Output>;
147 fn $fn(self, t: $F) -> Self::Output { 147 fn $fn(self, t: F) -> Self::Output {
148 let Pair(ref a, ref b) = self; 148 let Pair(ref a, ref b) = self;
149 Pair(a.$fn(t), b.$fn(t)) 149 Pair(a.$fn(t), b.$fn(t))
150 } 150 }
151 } 151 }
152 152
175 // } 175 // }
176 // } 176 // }
177 }; 177 };
178 } 178 }
179 179
180 impl_scalar!(Mul, mul, f32); 180 impl_scalar!(Mul, mul);
181 impl_scalar!(Mul, mul, f64); 181 //impl_scalar!(Mul, mul, f64);
182 impl_scalar!(Sub, sub, f32); 182 impl_scalar!(Sub, sub);
183 impl_scalar!(Sub, sub, f64); 183 //impl_scalar!(Sub, sub, f64);
184 184
185 macro_rules! impl_scalar_lhs { 185 macro_rules! impl_scalar_lhs {
186 ($trait:ident, $fn:ident, $F:ty) => { 186 ($trait:ident, $fn:ident, $F:ty) => {
187 impl<A, B> $trait<Pair<A, B>> for $F 187 impl<A, B> $trait<Pair<A, B>> for $F
188 where 188 where

mercurial