Last active
March 1, 2021 22:00
-
-
Save ciwolsey/24440dd2c09b585f799bf803f54b395d 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 Entity { | |
shape: Shape | |
} | |
enum Shape { | |
Square (u32), | |
Rectangle { width: u32, height: u32 }, | |
} | |
trait Area { | |
fn get_area(&self) -> u32; | |
} | |
impl Area for Entity { | |
fn get_area(&self) -> u32 { | |
match self.shape { | |
Shape::Rectangle { width, height } => width * height, | |
Shape::Square (width) => width * width, | |
} | |
} | |
} | |
fn main() { | |
let a = Entity { | |
shape: Shape::Rectangle { width: 3, height: 2 } | |
}; | |
let b = Entity { | |
shape: Shape::Square(3) | |
}; | |
println!("A: {}", a.get_area()); | |
println!("B: {}", b.get_area()); | |
} |
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 is never constructed: `Entity` | |
enum is never used: `Shape` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment