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?
&*foo
is called a "reborrow", and is idiomatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With