jpernst / rental

Rust macro to generate self-referential structs
Apache License 2.0
211 stars 11 forks source link

Rental with async/await methods #44

Closed ufoscout closed 4 years ago

ufoscout commented 4 years ago

I am upgrading an application to the new Postgres driver that uses async/await. This portion of the original code builds an object that holds a connection and a transaction linked to it:

fn new_simple_mut(
    conn: Connection,
) -> Result<rentals::SimpleMut, C3p0Error> {
    rentals::SimpleMut::try_new_or_drop(Box::new(conn), |c| {
        let tx = c.transaction()?;  <-- THIS FUNCTION IS ASYNC IN THE NEW DRIVER VERSION
        Ok(Some(tx))
    })
}

rental! {
    mod rentals {
        use super::*;

        #[rental_mut]
        pub struct SimpleMut {
            conn: Box<Connection>,
            tx: Option<Transaction<'conn>>,
        }
    }
}

In the new version of the Postgres driver, the connection.transaction() function is async so I should use .await but the try_new_or_drop does not accept it. Is there a way to achieve what I need with rental?

jpernst commented 4 years ago

I haven't used rust in a few years and am unfamiliar with how the async/await feature works, so I can't offer any specific advice here, unfortunately.

Stargateur commented 4 years ago

Is this a reason to close this ?