Created
October 7, 2019 15:51
-
-
Save alexreg/2e47ba39c1bd5b3a4dcfff5d2e5660e5 to your computer and use it in GitHub Desktop.
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
// #![feature(trait_upcasting)] | |
use std::sync::Arc; | |
trait Foo: std::fmt::Display { | |
fn a(&self) { | |
println!("Foo::a -- {}", self); | |
} | |
} | |
trait Bar: Foo { | |
fn a(&self) { | |
println!("Bar::a -- {}", self); | |
} | |
fn b(&self) { | |
println!("Bar::b -- {}", self); | |
} | |
} | |
impl Foo for i32 {} | |
impl Bar for i32 {} | |
fn main() { | |
let bar: &dyn Bar = &21; | |
let foo: &dyn Foo = bar; | |
foo.a(); | |
println!("foo: {}", foo); | |
Bar::a(bar); | |
bar.b(); | |
let bar: Arc<dyn Bar> = Arc::new(42); | |
println!("Arc-bar: {}", bar); | |
let foo: Arc<dyn Foo> = bar; | |
println!("Arc-foo: {}", foo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment