-
-
Save mverleg/788a9945b060eb01283ed3d6068c9c31 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
// Unfortunately no polymorphism | |
struct Alpha {} | |
trait Beta { | |
fn p(&self, z: &Beta) -> bool; | |
} | |
trait Gamma: Beta {} | |
impl Beta for Alpha { | |
fn p(&self, z: &Beta) -> bool { | |
true | |
} | |
} | |
impl Gamma for Alpha {} | |
fn main() { | |
let x: &Gamma = &Alpha {}; | |
let y: &Beta = x; | |
println!("{}", x.p(x)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment