struct Point { x: f32, y: f32, } trait Display { fn display(&self); } impl Display for Point{ fn display(&self) { println!("({},{})", self.x, self.y) } } impl Display for f64 { fn display(&self) { println!("Float {}", self) } } // This function receives a trait object (dynamic dispatch!) fn f(v: &dyn Display) { println!("f()!!!"); v.display() } fn main() { let p = Point{x: 1.0,y:1.0}; let v = 6.28; p.display(); f(&p); f(&v) }