]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
1 | use std::ops::Mul; |
2 | ||
3 | #[derive(Copy, Clone)] | |
4 | pub struct Foo { | |
5 | x: f64, | |
6 | } | |
7 | ||
8 | impl Mul<Foo> for f64 { | |
9 | type Output = Foo; | |
10 | ||
11 | fn mul(self, rhs: Foo) -> Foo { | |
12 | // intentionally do something that is not * | |
13 | Foo { x: self + rhs.x } | |
85aaf69f | 14 | } |
223e47cc | 15 | } |
c34b1796 AL |
16 | |
17 | pub fn main() { | |
18 | let f: Foo = Foo { x: 5.0 }; | |
19 | let val: f64 = 3.0; | |
20 | let f2: Foo = val * f; | |
21 | assert_eq!(f2.x, 8.0); | |
22 | } |