Created
February 1, 2022 09:27
-
-
Save little-dude/1944801e5f55e76a9c190bef93063674 to your computer and use it in GitHub Desktop.
dyn Trait + OtherTrait
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
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