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?

kmdreko
  • 42,554
  • 6
  • 57
  • 106
anjruu
  • 1,224
  • 10
  • 24

1 Answers1

6

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

Veedrac
  • 58,273
  • 15
  • 112
  • 169
  • 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