Created
March 14, 2023 15:30
-
-
Save computermouth/484bcdc5f416e8c9e007efce651563cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Point { | |
x: isize, | |
y: isize, | |
} | |
struct Circle { | |
center: Point, | |
radius: f64, | |
} | |
struct Triangle { | |
points: [Point; 3] | |
} | |
struct Square { | |
points: [Point; 4] | |
} | |
trait Shape { | |
fn draw(&self); | |
} | |
impl Shape for Circle { | |
fn draw(&self){ | |
_ = self.center; | |
_ = self.radius; | |
} | |
} | |
impl Shape for Triangle { | |
fn draw(&self){ | |
_ = self.points[2].x; | |
_ = self.points[2].y; | |
} | |
} | |
impl Shape for Square { | |
fn draw(&self){ | |
_ = self.points[3].x; | |
_ = self.points[3].y; | |
} | |
} | |
fn main() { | |
let circ = Circle { | |
center: Point { x: 0, y: 0 }, | |
radius: 1.0, | |
}; | |
let tri = Triangle { | |
points: [ | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
], | |
}; | |
let sq = Square { | |
points: [ | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
] | |
}; | |
circ.draw(); | |
tri.draw(); | |
sq.draw(); | |
println!("Hello, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment