3

How do I call a function that expects a trait object if I have a Box<T> instead? In other words:

trait T { ... }

fn func(t: &T) { ... }

fn some_other_func() {
   b: Box<T>; // Provided

   // These work, but is there a better way?
   func( &*b );                // 1
   func( Borrow::borrow(&b) ); // 2
}

Both 1 and 2 seem wrong. Am I missing something obvious?

anjruu
  • 1,164
  • 8
  • 22

1 Answers1

6

&*foo is called a "reborrow", and is idiomatic.

Veedrac
  • 54,508
  • 14
  • 106
  • 164
  • Alrighty then. I guess I was scared off just because it looked so very wrong to my poor C++-trained eyes. Thanks! – anjruu Aug 19 '15 at 01:44