Skip to content

Conversation

@Dav1dde
Copy link
Member

@Dav1dde Dav1dde commented Nov 26, 2024

DESCRIBE YOUR PR

Async traits exist for a year now. We should use them.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

@vercel
Copy link

vercel bot commented Nov 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
develop-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 0:11am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Nov 26, 2024 0:11am
sentry-docs ⬜️ Ignored (Inspect) Visit Preview Nov 26, 2024 0:11am

@Dav1dde Dav1dde requested review from a team and jan-auer November 26, 2024 11:23
Co-authored-by: Riccardo Busetti <riccardob36@gmail.com>
trait Database {
fn get_user(&self) -> Pin<Box<dyn Future<Output = User> + Send + '_>>;
pub trait Database {
fn get_user(&self) -> impl Future<Output = User> + Send;
Copy link
Member

@jan-auer jan-auer Nov 26, 2024

Choose a reason for hiding this comment

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

Wanna add a callout here why we should be explicit with Send and Sync and prefer impl Future over async for that reason in trait definitions?

Personally, I'd add a recommendation to use associated types where possible (especially for Iterators!) as this is extremely useful for composition in the absence of generators, but for async there's simply no need to create named futures in most cases.

Copy link
Member Author

@Dav1dde Dav1dde Nov 26, 2024

Choose a reason for hiding this comment

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

Wanna add a callout here why we should be explicit with Send and Sync and prefer impl Future over async for that reason?

I kept this message, hoping it would address this clearly enough:

Note that the returned future type is Send, to ensure that it can run on a multi-threaded runtime.


Personally, I'd add a recommendation to name types where possible (especially for Iterators!) as this is extremely useful for composition in the absence of generators [...]

This requires explicit associated types until this restriction is lifted. I think for most of Sentry's (application) code this would be overkill. I can add another note that explains that as well.

@Dav1dde
Copy link
Member Author

Dav1dde commented Dec 4, 2024

Merging this, can work on the GAT variant in a followup.

@Dav1dde Dav1dde merged commit 50575e3 into master Dec 4, 2024
10 checks passed
@Dav1dde Dav1dde deleted the dav1d/rust-async-trait branch December 4, 2024 07:34
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants