Skip to content

Use AsyncFnOnce instead of FnOnce -> RetFut #5

Closed
@touilleMan

Description

@touilleMan

Async closure has been stabilized in Rust 1.85 this brings a much better ergonomic when passing reference to a closure.

For instance currently this wrapper is not possible (but would be fine if TransactionBuilder::run would accept an async closure):

struct WrapperDatabase {
    pub async fn for_update<R, E>(
        &mut self,
        cb: impl AsyncFnOnce(TransactionWrapper),
    ) {
        self.conn.transaction(&["store"])
            .run(async move |transaction| {
                let wrapper = TransactionWrapper(transaction);
                cb(wrapper).await
                Ok(())
            })
            .await.unwrap();
    }
}

Rust compilation error:

the parameter type `impl AsyncFnOnce(TransactionWrapper)` must be valid for the static lifetime...
...so that the type `impl AsyncFnOnce(TransactionWrapper)` will meet its required lifetime bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions