Skip to content

Commit d9fd52b

Browse files
committed
review: use &mut self method receivers
this applies a review suggestion here: https://github.com/hyperium/http-body/pull/100/files#r1399780355 this commit refactors the channel-backed body in #100, changing the signature of `send_*` methods on the sender to require a mutable reference.
1 parent 42d8f26 commit d9fd52b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

http-body-util/src/channel.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ pub struct Sender<D, E = std::convert::Infallible> {
7979

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

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

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

@@ -132,7 +132,7 @@ mod tests {
132132

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

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

0 commit comments

Comments
 (0)