Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace async_trait with native async fns #230

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

gahag-cw
Copy link
Contributor

@gahag-cw gahag-cw commented Dec 3, 2024

Note that the usage of CustomizeConnection requires it to be object safe, and thus we need to use boxed futures instead of plain async fns.

@gahag-cw
Copy link
Contributor Author

gahag-cw commented Dec 3, 2024

@djc we have an issue with the coverage pipeline:

There was an error running the uploader: Error uploading to [https://codecov.io:](https://codecov.io/) Error: There was an error fetching the storage URL during POST: 429 - {"message":"Rate limit reached. Please upload with the Codecov repository upload token to resolve issue. Expected time to availability: 2144s."}

Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks good to me. Please squash into two commits:

  1. MSRV bump
  2. All the code changes

bb8/src/api.rs Outdated
@@ -406,8 +408,12 @@ pub trait CustomizeConnection<C: Send + 'static, E: 'static>:
///
/// The default implementation simply returns `Ok(())`. If this method returns an
/// error, it will be forwarded to the configured error sink.
async fn on_acquire(&self, _connection: &mut C) -> Result<(), E> {
Ok(())
fn on_acquire<'a, 'b, 'r>(&'a self, _connection: &'b mut C) -> BoxFuture<'r, Result<(), E>>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we spell this <'r, 'a: 'r, 'b: 'r> instead? And do we really need the 3 separate lifetimes?

Why is BoxFuture useful? Could we just do Box<dyn Future<..>> instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoxFuture<'a, T> is actually Pin<Box<dyn Future<Output = T> + Send + 'a>>. I'll apply the suggestions.

Copy link
Contributor Author

@gahag-cw gahag-cw Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And do we really need the 3 separate lifetimes?

I'm not sure, but that's what async_trait generated, so I kept it to prevent further breaking changes in the API.

@djc
Copy link
Owner

djc commented Dec 6, 2024

I think #231 has solved the coverage issue, please rebase on top of current main.

@gahag-cw gahag-cw force-pushed the feat/remove-async-trait branch from e88d79c to 7343297 Compare December 6, 2024 16:15
@gahag-cw
Copy link
Contributor Author

gahag-cw commented Dec 6, 2024

@djc I applied the following suggested changes:

  • squash into MSRV bump and code changes commits
  • change on_acquire lifetimes to <'r, 'a: 'r, 'b: 'r>
  • replace all usages of BoxFuture<'r, Result<(), Error>> with Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'r>>

Let me know if you have any further suggestions.

@gahag-cw gahag-cw force-pushed the feat/remove-async-trait branch from 7343297 to 148d27a Compare December 6, 2024 16:18
bb8/src/api.rs Outdated Show resolved Hide resolved
@djc
Copy link
Owner

djc commented Dec 6, 2024

Please also add a separate commit that bumps all the version numbers.

@gahag-cw gahag-cw force-pushed the feat/remove-async-trait branch from 148d27a to dce257b Compare December 6, 2024 19:05
@gahag-cw gahag-cw force-pushed the feat/remove-async-trait branch from dce257b to 8c104dd Compare December 6, 2024 19:06
@gahag-cw
Copy link
Contributor Author

gahag-cw commented Dec 6, 2024

@djc done.

@djc djc merged commit 6e2a586 into djc:main Dec 6, 2024
@djc
Copy link
Owner

djc commented Dec 6, 2024

Thanks!

@djc
Copy link
Owner

djc commented Dec 9, 2024

  • Published bb8 v0.9.0 at registry crates-io
  • Published bb8-postgres v0.9.0 at registry crates-io
  • Published bb8-redis v0.18.0 at registry crates-io
  • [new tag] v0.9.0 -> v0.9.0
  • Release notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants