-
-
Save ZhangHanDong/a43619136f22f6092ff10534f966b247 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
trait A{ | |
fn a(&self); | |
} | |
trait B{ | |
fn b(&self); | |
} | |
impl B for A{ | |
fn b(&self){ | |
println!("B1"); | |
self.a(); | |
} | |
} | |
impl B for &A{ | |
fn b(&self){ | |
println!("B2"); | |
(*self).a(); | |
} | |
} | |
struct S; | |
impl A for S{ | |
fn a(&self){ | |
println!("S"); | |
} | |
} | |
fn t<T: B+?Sized>(a: &T) { | |
a.b(); | |
} | |
fn main() { | |
let a:&dyn A = &S; | |
let b:&dyn B = &a; | |
b.b(); | |
t(a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment