Skip to content

docs(example)/custom future with multiple bodies#711

Open
Reza-Darius wants to merge 3 commits into
tower-rs:mainfrom
Reza-Darius:docs(example)/custom-future-multiple-bodies
Open

docs(example)/custom future with multiple bodies#711
Reza-Darius wants to merge 3 commits into
tower-rs:mainfrom
Reza-Darius:docs(example)/custom-future-multiple-bodies

Conversation

@Reza-Darius

Copy link
Copy Markdown

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

  • removed BoxBody alias
  • removed some service trait bounds
  • added helper functions
  • replaced Pin Box Future with custom future.
  • added asserts to 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 Either which states that both arms need to have the same underlying Data type. 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 the Data types mismatch.

tower-http/limit imposes a Body<Data = Bytes> bound on its Body implementation for it's wrapper type and im wondering whether this example should include it too, and if so, where.

@Isvane

Isvane commented Jul 8, 2026

Copy link
Copy Markdown
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?

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