Skip to content

Instantly share code, notes, and snippets.

@little-dude
Created February 1, 2022 09:27
Show Gist options
  • Save little-dude/1944801e5f55e76a9c190bef93063674 to your computer and use it in GitHub Desktop.
Save little-dude/1944801e5f55e76a9c190bef93063674 to your computer and use it in GitHub Desktop.
dyn Trait + OtherTrait
use std::fmt::Debug;
trait MyTrait: Debug {
fn m(&self);
}
#[derive(Debug)]
struct Foo;
impl MyTrait for Foo {
fn m(&self) {}
}
impl MyTrait for Box<dyn MyTrait> {
fn m(&self) {
(**self).m()
}
}
fn main() {
let boxed_foo: Box<dyn MyTrait> = Box::new(Foo);
println!("{:?}", boxed_foo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment