docs(example)/custom future with multiple bodies#711
Open
Reza-Darius wants to merge 3 commits into
Open
Conversation
Contributor
|
Thanks so much for iterating on this! ngl im still learning so custom futures and tower trait bounds are still kinda wizardry to me lol. your version looks way cleaner and more idiomatic. Should i just close my pr so we can use yours? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on this PR, which explores idomatic solutions to dealing with multiple HTTP bodies in tower services
Motivation
@Isvane did a great job with his proposal, so i wanted to iterate on it by bringing it closer to how i solved this problem in my own project. Primarily, by introducing a custom future.
Changes
BoxBodyaliasservicetrait boundsPin Box Futurewith custom future.main()Discussion
While i think this is a decently elegant solution, it could be argued its not idiomatic if you compare how this problem is solved in
tower-http/limit.A potential foot gun im wondering about is the trait bound on
Eitherwhich states that both arms need to have the same underlyingDatatype. Right now the example leaves the response body of the inner service entirely generic, but this could lead to a nasty compile error down the road should theDatatypes mismatch.tower-http/limitimposes aBody<Data = Bytes>bound on itsBodyimplementation for it's wrapper type and im wondering whether this example should include it too, and if so, where.