How to .await a Reference on Self Without Manually Wrapping like `(&self.future).await`?
⚓ Rust 📅 2025-08-30 👤 surdeus 👁️ 11I've got a struct Conn which I can implement Future on, but that I can can also implement Future for &Conn instead, and that is convenient because I want to await on it several times in methods on a parent struct, for example, I want to be able to do self.conn.await.some_function().
The ergonomics problem I'm running into is that calling self.conn.await tries to take ownership of self.conn and I can only get around it by calling (&self.conn).await, which is annoying.
Ironically it seems that the easiest way to fix the problem is to add a get() helper method on Conn:
fn get(&self) -> &Self { self }
Then I just call self.conn.get().await.
Are there any ways I can convince the compiler to let me await on the reference while only having to type self.conn.await?
It's not that big a deal I suppose, but I tried everything I could think of and it doesn't look possible so I figured I'd ask and make sure.
3 posts - 2 participants
🏷️ Rust_feed