Skip to content

Instantly share code, notes, and snippets.

@Spindel
Created July 29, 2024 19:01
Show Gist options
  • Save Spindel/2f3dbd8323af331064bb3360bbb0211a to your computer and use it in GitHub Desktop.
Save Spindel/2f3dbd8323af331064bb3360bbb0211a to your computer and use it in GitHub Desktop.
Bloody traits and traitorous traits....
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