MCPcopy Create free account
hub / github.com/derekbanas/Rust-Tutorial / Shape

Interface Shape

main.rs:686–692  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Implementers 1

mainmain.rs

Calls

no outgoing calls

Tested by

no test coverage detected