main.rs
1 struct Point<X1, Y1> { 2 x: X1, 3 y: Y1, 4 } 5 6 impl<X1, Y1> Point<X1, Y1> { 7 fn mixup<X2, Y2>(self, other: Point<X2, Y2>) -> Point<X1, Y2> { 8 Point { 9 x: self.x, 10 y: other.y, 11 } 12 } 13 } 14 15 fn main() { 16 let p1 = Point { x: 5, y: 10.4 }; 17 let p2 = Point { x: "Hello", y: 'c' }; 18 19 let p3 = p1.mixup(p2); 20 21 println!("p3.x = {}, p3.y = {}", p3.x, p3.y); 22 }