We can tie struct properties to functions using Traits You can create functions that can be used by any structs that implement the right traits
| 684 | // You can create functions that can be used by any structs |
| 685 | // that implement the right traits |
| 686 | trait Shape { |
| 687 | // This is a constructor which returns a Shape |
| 688 | fn new(length: f32, width: f32) -> Self; |
| 689 | |
| 690 | // An area function that belongs to this trait |
| 691 | fn area(&self) -> f32; |
| 692 | } |
| 693 | |
| 694 | // Define rectangle and circle struct |
| 695 | struct Rectangle {length: f32, width: f32} |
nothing calls this directly
no outgoing calls
no test coverage detected