Skip to content

feat(util): introduce Chain<A, B> - #178

Open
cratelyn wants to merge 1 commit into
masterfrom
chain
Open

feat(util): introduce Chain<A, B>#178
cratelyn wants to merge 1 commit into
masterfrom
chain

Conversation

@cratelyn

@cratelyn cratelyn commented Aug 28, 2026

Copy link
Copy Markdown
Member

this commit introduces a new body middleware, Chain<A, B>.

similar to std::iter::Iterator::chain(), this provides an adapter to join two bodies together. a new BodyExt::chain() trait method is introduced as a facility to create a chained body using a.chain(b) syntax.

that method will return a new http_body::Body that emits the contents of the first body, and then emits the contents of the second body. if the first body returns an error, the body will consider itself finished and will not poll the second body.

a test suite is included to confirm that this properly handles state transitions for empty bodies, errors, and trailers. the test suite also includes assertions to show that hints (is_end_stream() and size_hint()) work properly.

@cratelyn

This comment was marked as outdated.

this commit introduces a new body middleware, `Chain<A, B>`.

similar to [`std::iter::Iterator::chain()`], this provides an adapter to
join two bodies together. a new [`BodyExt::chain()`] trait method is
introduced as a facility to create a chained body using `a.chain(b)`
syntax.

that method will return a new [`Body`][http_body::Body] that emits the
contents of the first body, and then emits the contents of the second
body.

If the first body returns an error, the body will consider itself
finished and will not poll the second body.

a test suite is included to confirm that this properly handles state
transitions for empty bodies, errors, and trailers. the test suite also
includes assertions to show that hints (`is_end_stream()` and
`size_hint()`) work properly.

Signed-off-by: katelyn martin <git@katelyn.world>
@cratelyn
cratelyn marked this pull request as ready for review August 28, 2026 15:54
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.

1 participant