Created
July 29, 2024 19:01
-
-
Save Spindel/2f3dbd8323af331064bb3360bbb0211a to your computer and use it in GitHub Desktop.
Bloody traits and traitorous traits....
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
trait MustHave {} | |
trait First: MustHave {} | |
trait Second: MustHave {} | |
trait Final: MustHave {} | |
impl Final for dyn First {} | |
impl Final for dyn Second {} | |
struct A{} | |
impl MustHave for A{} | |
struct B{} | |
impl MustHave for B{} | |
struct C{} | |
impl MustHave for C{} | |
impl First for A{} | |
impl Second for B{} | |
impl Final for C{} | |
fn cast_a(f: Box<dyn First>) -> Box<dyn Final> { | |
let d: Box<dyn Final> = f; | |
d | |
} | |
fn makeit() -> (Box<dyn Final>, Box<dyn Final>, Box<dyn Final>) { | |
let a = A{}; | |
let b = B{}; | |
let c = C{}; | |
(Box::new(a) as Box<dyn First>, Box::new(b), Box::new(c)) | |
} | |
fn main() { | |
println!("Hello, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment