trait Dimension { fn volume(&self) -> f64; } struct Sphere { radius: f64 } impl Dimension for Sphere { fn volume(&self) -> f64 { 4.0/3.0 * std::f64::consts::PI * cubic(self.radius) } } struct Cube { side: f64 } impl Dimension for Cube { fn volume(&self) -> f64 { cubic(self.side) } } fn print_volume(obj: T) { println!("Das Objekt hat das Volumen von {}", obj.volume()); } fn cubic(x: f64) -> f64 { x * x * x } fn main() { print_volume(Sphere { radius: 1.0}); print_volume(Cube { side: 1.0 }); }