Created
October 26, 2023 12:28
-
-
Save andy-thomason/d125852558e5b5c48bd31e3d4b37ff3c to your computer and use it in GitHub Desktop.
Animal trait
This file contains 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
trait Animal { | |
fn number_of_legs(&self) -> i32; | |
fn speak(&self) -> String; | |
fn eat(&mut self); | |
} | |
struct Cat { | |
} | |
struct Dog { | |
} | |
impl Animal for Cat { | |
fn number_of_legs(&self) -> i32 { | |
todo!() | |
} | |
fn speak(&self) -> String { | |
todo!() | |
} | |
fn eat(&mut self) { | |
todo!() | |
} | |
} | |
#[test] | |
fn test_cat() { | |
let cat = Cat { }; | |
assert_eq!(cat.speak(), "Meow"); | |
} | |
#[test] | |
fn test_dog() { | |
let cat = Cat { }; | |
assert_eq!(cat.speak(), "Meow"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment