palantir / conjure-rust

Conjure support for Rust
Apache License 2.0
20 stars 11 forks source link

[stacked] Stop using #[async_trait] in conjure-http #280

Closed sfackler closed 9 months ago

sfackler commented 10 months ago

Before this PR

All async traits in the Conjure HTTP API had to be defined using the #[async_trait] macro. This caused the rustdoc output to be pretty unfriendly due to how the macro rewrote the trait definition, and required all futures to be boxed.

After this PR

==COMMIT_MSG== The async conjure-http traits no longer use the #[async_trait] macro. ==COMMIT_MSG==

With Rust 1.75's support for impl trait return types in traits, we can avoid the need for #[async_trait] and define the APIs in a more normal way.

Due to limitations in the current implementation in the compiler, we have to force all returned futures to be Sync in the trait definitions. This limitation will hopefully be lifted some time in 2024.

impl trait-returning methods are not object-safe, so the PR defines BoxAsyncFoo structs which type-erase an AsyncFoo implementation for the traits requiring that - in particular AsyncEndpoint and AsyncWriteBody.

The custom client and endpoints traits used with conjure_macros are still expected to use #[async_trait]. I will change that in a follow-up PR.

changelog-app[bot] commented 9 months ago

Generate changelog in changelog-dir>`changelog/@unreleased`</changelog-dir

What do the change types mean? - `feature`: A new feature of the service. - `improvement`: An incremental improvement in the functionality or operation of the service. - `fix`: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way. - `break`: Has the potential to break consumers of this service's API, inclusive of both Palantir services and external consumers of the service's API (e.g. customer-written software or integrations). - `deprecation`: Advertises the intention to remove service functionality without any change to the operation of the service itself. - `manualTask`: Requires the possibility of manual intervention (running a script, eyeballing configuration, performing database surgery, ...) at the time of upgrade for it to succeed. - `migration`: A fully automatic upgrade migration task with no engineer input required. _Note: only one type should be chosen._
How are new versions calculated? - ❗The `break` and `manual task` changelog types will result in a major release! - 🐛 The `fix` changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease. - ✨ All others will result in a minor version release.

Type

- [ ] Feature - [ ] Improvement - [ ] Fix - [x] Break - [ ] Deprecation - [ ] Manual task - [ ] Migration

Description

The async conjure-http traits no longer use the `#[async_trait]` macro. **Check the box to generate changelog(s)** - [x] Generate changelog entry