title: How to implement the Debug trait for struct that has a trait object member?
body: <p>My goal is printing the contents of struct that has trait object member but I can't find how to tell Rust compiler that the member also implements other traits like <code>Display</code> or <code>Debug</code>.</p>
  
  <p>For example, in the following program, I want to print the structure of <code>S2</code> (and <code>S1</code> for comparison) but I get stuck in the implementation of <code>fmt</code>.</p>
  
  <pre class="lang-rust prettyprint-override"><code>trait Tr {}
  
  impl Tr for usize {}
  
  impl Tr for String {}
  
  #[derive(Debug)]
  struct S1&lt;A: Tr + std::fmt::Debug&gt; {
      member: Box&lt;A&gt;,
  }
  
  struct S2 {
      member: Box&lt;Tr&gt;,
  }
  
  impl std::fmt::Debug for S2 {
      fn fmt(&amp;self, fmt: &amp;mut std::fmt::Formatter&lt;'_&gt;) -&gt; Result&lt;(), std::fmt::Error&gt; {
          // ??
          Ok(())
      }
  }
  
  fn main() {
      let s1 = S1 {
          member: Box::new(String::from("abc")),
      };
  
      println!("{:?}", s1);
  
      let s2 = S2 {
          member: Box::new(String::from("abc")),
      };
  
      println!("{:?}", s2);
  }
  </code></pre>
  
  <p>My desired output of this program is</p>
  
  <pre class="lang-none prettyprint-override"><code>S1 { member: "abc" }
  S2 { member: "abc" }
  </code></pre>
  
  <p>Is it possible to implement <code>Debug</code> for a struct like <code>S2</code>?</p>
  
  <p>(Rust version: 1.35)</p>