diff --git a/src/main.rs b/src/main.rs index 23bc058..65b2fbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,6 +51,12 @@ struct BouncingImage { rate: u32, } +trait Drawable { + // Associated function signature; `Self` refers to the implementor type. + + fn draw_and_move(&mut self, display: &mut Display); + +} impl BouncingImage { /// Initializes a new BouncingImage. fn new(img_file: &str, move_x: i32, move_y: i32, rate: u32, start_x: i32, start_y: i32) -> Self { @@ -75,7 +81,8 @@ impl BouncingImage { } bb } - +} +impl Drawable for BouncingImage { /// Draws the image and updates its position. fn draw_and_move(&mut self, display: &mut Display) { display.draw_png(&self.img, self.x, self.y);