Created
March 6, 2017 19:04
-
-
Save Latrasis/d6710a13000cb18e5efb2da2fdfa6536 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct Animal {}; | |
type Cat = Animal; | |
type Dog = Animal; | |
impl ToString for Animal { | |
fn to_string(&self) -> String { | |
"Animal".to_string() | |
} | |
} | |
impl ToString for Cat { | |
fn to_string(&self) -> String { | |
"Cat".to_string() | |
} | |
} | |
impl ToString for Dog { | |
fn to_string(&self) -> String { | |
"Dog".to_string() | |
} | |
} | |
fn main() { | |
let animal = Animal {}; | |
// "Animal" | |
println!("{:}", animal); | |
// "Cat" | |
println!("{:}", animal as Cat); | |
// "Dog" | |
println!("{:}", animal as Dog); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment