Skip to content

Instantly share code, notes, and snippets.

@andy-thomason
Created October 26, 2023 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy-thomason/d125852558e5b5c48bd31e3d4b37ff3c to your computer and use it in GitHub Desktop.
Save andy-thomason/d125852558e5b5c48bd31e3d4b37ff3c to your computer and use it in GitHub Desktop.
Animal trait
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