Tuple Structs
Exercises
Definition
Description
This is a helpful description. Read me to understand what to do!
// Complete the structure definition. struct Point impl Point { fn on_x_axis(&self) -> bool { self.1 == 0.0 } fn on_y_axis(&self) -> bool { self.0 == 0.0 } } fn main() { let point = Point(0.0, 0.0); if point.on_x_axis() && point.on_y_axis() { println!("Point is origin"); } }
Hint 1
This is a helpful hint! Read me to understand what to do!
Hint 2
This is a helpful hint! Read me to understand what to do!
Hint 3
This is a helpful hint! Read me to understand what to do!
Solution
struct Point(f32, f32); impl Point { fn on_x_axis(&self) -> bool { self.1 == 0.0 } fn on_y_axis(&self) -> bool { self.0 == 0.0 } } fn main() { let point = Point(0.0, 0.0); if point.on_x_axis() && point.on_y_axis() { println!("Point is origin"); } }