Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: add a channel body #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

cratelyn
Copy link

@cratelyn cratelyn commented Jan 6, 2025

this branch represents a revival of #100, applying changes that were suggested in review. in particular, see 08aba95 and 4fed62f.

changes

use sync::oneshot for error channel

this commit refactors the channel-backed body in #100, changing the
mpsc::Receiver<E> used to transmit an error into a
oneshot::Receiver<E>.

this should improve memory usage, and make the channel a smaller
structure.

in order to achieve this, some minor adjustments are made:

  • use pin projection, projecting pinnedness to the oneshot receiver,
    polling it via core::future::Future::poll(..) to yield a body frame.

  • add Debug bounds were needed.

use &mut self method receivers

this commit refactors the channel-backed body in #100, changing the
signature of send_* methods on the sender to require a mutable
reference.

@cratelyn
Copy link
Author

cratelyn commented Jan 8, 2025

the msrv action failed here: https://github.com/hyperium/http-body/actions/runs/12635582609/job/35249835531

the relevant bit of our manifest getting in the way is the dep: prefix syntax, noted as being available only after rust 1.60. see the cargo book here: https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies

4a5b234 removes this syntax, to be backwards compatible with older rust versions.

davidpdrsn and others added 3 commits January 8, 2025 17:27
this applies a review suggestion here:
https://github.com/hyperium/http-body/pull/100/files#r1399781061

this commit refactors the channel-backed body in hyperium#100, changing the
`mpsc::Receiver<E>` used to transmit an error into a
`oneshot::Receiver<E>`.

this should improve memory usage, and make the channel a smaller
structure.

in order to achieve this, some minor adjustments are made:

* use pin projection, projecting pinnedness to the oneshot receiver,
  polling it via `core::future::Future::poll(..)` to yield a body frame.

* add `Debug` bounds were needed.

as an alternative, see tokio-rs/tokio#7059, which proposed a
`poll_recv(..)` inherent method for a oneshot channel receiver.
this applies a review suggestion here:
https://github.com/hyperium/http-body/pull/100/files#r1399780355

this commit refactors the channel-backed body in hyperium#100, changing the
signature of `send_*` methods on the sender to require a mutable
reference.
@cratelyn
Copy link
Author

cratelyn commented Jan 8, 2025

ah, i just saw that #128 was merged yesterday. i've rebased on top of that, so we can use the dep: syntax in conditional dependencies. nice!

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