Skip to content

Instantly share code, notes, and snippets.

@computermouth
Created March 14, 2023 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computermouth/484bcdc5f416e8c9e007efce651563cd to your computer and use it in GitHub Desktop.
Save computermouth/484bcdc5f416e8c9e007efce651563cd to your computer and use it in GitHub Desktop.
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