Created
November 26, 2019 06:18
-
-
Save rust-play/d0de5fc75d85870a8f0aadd317c8c26d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
fn main() { | |
println!("Hello, world!"); | |
} | |
fn test(holder: Holder) -> impl Animal { | |
match holder { | |
Holder::DogHolder(dog) => dog, | |
Holder::CatHolder(cat) => cat, | |
} | |
} | |
struct Dog; | |
struct Cat; | |
enum Holder { | |
DogHolder(Dog), | |
CatHolder(Cat), | |
} | |
impl Animal for Dog { | |
fn hello(self) -> usize { | |
1 | |
} | |
} | |
impl Animal for Cat { | |
fn hello(self) -> usize { | |
2 | |
} | |
} | |
trait Animal { | |
fn hello(self) -> usize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment