// Double generic types for a struct pub struct DoubleGenericPoint { pub x: T, pub y: U, } impl DoubleGenericPoint { // Takes a generic of potentially different types than the parent struct pub fn mixup(self, other: DoubleGenericPoint) -> DoubleGenericPoint { DoubleGenericPoint { x: self.x, y: other.y } } } pub struct Point { pub x: T, pub y: T, } // Implement generic methods on a generic struct impl Point { pub fn x(&self) -> &T { &self.x } } // Implement a method for only a specific type of generic impl Point { fn distance_from_origin(&self) -> f32 { (self.x.powi(2) + self.y.powi(2)).sqrt() } }