I'm trying to find a way to more cleanly call the function of an associated type of my trait. I have, for example, this trait:
trait Connection {
fn new(...) -> Self;
}
It is an associated type of another trait:
trait ConnectionPool {
type Connection: Connection;
fn new_connection(...) -> Self::Connection {
<Self::Connection as Connection>::new(...)
}
}
My issue is that I can't use Self::Connection::new
, I have to use a cast, otherwise the compiler is not sure which trait I'm referencing (even though there is only one option)- is there a way to avoid this?
I've tried writing a macro to at least make this a little cleaner (This situation happens a few times in my code base), but I couldn't find a way to do it, since a macro has to generate a complete statement- The macro would've to also do the function call.