Skip to content

Commit

Permalink
review: use &mut self method receivers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cratelyn committed Jan 6, 2025
1 parent 08aba95 commit 4fed62f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions http-body-util/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ pub struct Sender<D, E = std::convert::Infallible> {

impl<D, E> Sender<D, E> {
/// Send a frame on the channel.
pub async fn send(&self, frame: Frame<D>) -> Result<(), SendError> {
pub async fn send(&mut self, frame: Frame<D>) -> Result<(), SendError> {
self.tx_frame.send(frame).await.map_err(|_| SendError)
}

/// Send data on data channel.
pub async fn send_data(&self, buf: D) -> Result<(), SendError> {
pub async fn send_data(&mut self, buf: D) -> Result<(), SendError> {
self.send(Frame::data(buf)).await
}

/// Send trailers on trailers channel.
pub async fn send_trailers(&self, trailers: HeaderMap) -> Result<(), SendError> {
pub async fn send_trailers(&mut self, trailers: HeaderMap) -> Result<(), SendError> {
self.send(Frame::trailers(trailers)).await
}

Expand Down Expand Up @@ -132,7 +132,7 @@ mod tests {

#[tokio::test]
async fn works() {
let (tx, body) = Channel::<Bytes>::new(1024);
let (mut tx, body) = Channel::<Bytes>::new(1024);

tokio::spawn(async move {
tx.send_data(Bytes::from("Hel")).await.unwrap();
Expand Down

0 comments on commit 4fed62f

Please sign in to comment.