Skip to content

Instantly share code, notes, and snippets.

@mverleg
Forked from rust-play/playground.rs
Created April 10, 2018 20:58
Show Gist options
  • Save mverleg/788a9945b060eb01283ed3d6068c9c31 to your computer and use it in GitHub Desktop.
Save mverleg/788a9945b060eb01283ed3d6068c9c31 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
// 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