Created
December 24, 2020 01:05
-
-
Save alecchendev/f2b141fb71520ed455e093f98379ce4d to your computer and use it in GitHub Desktop.
OOP in rust article - impl animal enum
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
impl Animal { | |
fn speak(&self) { | |
match self { | |
Animal::Dog(_) => println!("Woof!"), | |
Animal::Cat(_) => println!("Meow!"), | |
Animal::Pig(_) => println!("Oink!"), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment