Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 26, 2019 06:18
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 rust-play/d0de5fc75d85870a8f0aadd317c8c26d to your computer and use it in GitHub Desktop.
Save rust-play/d0de5fc75d85870a8f0aadd317c8c26d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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