diff --git a/quinn-h3/src/body.rs b/quinn-h3/src/body.rs index 5088603fc..a363931ab 100644 --- a/quinn-h3/src/body.rs +++ b/quinn-h3/src/body.rs @@ -39,28 +39,23 @@ use crate::{ /// /// [`http::Request`]: https://docs.rs/http/*/http/request/index.html /// [`http::Response`]: https://docs.rs/http/*/http/response/index.html -pub enum Body { - /// Inexistent body - None, - /// Buffer-contained body - Buf(Bytes), -} +pub struct Body(pub(crate) Option); impl From<()> for Body { fn from(_: ()) -> Self { - Body::None + Body(None) } } impl From for Body { fn from(buf: Bytes) -> Self { - Body::Buf(buf) + Body(Some(buf)) } } impl From<&str> for Body { fn from(buf: &str) -> Self { - Body::Buf(Bytes::copy_from_slice(buf.as_ref())) + Body(Some(Bytes::copy_from_slice(buf.as_ref()))) } } @@ -360,7 +355,7 @@ impl BodyWriter { /// let mut trailers = HeaderMap::new(); /// trailers.insert("trailing", "here".parse()?); /// body_writer.trailers(trailers).await?; - /// + /// /// Ok(()) /// } /// ``` diff --git a/quinn-h3/src/client.rs b/quinn-h3/src/client.rs index b0e9bb0f5..1901665d6 100644 --- a/quinn-h3/src/client.rs +++ b/quinn-h3/src/client.rs @@ -450,7 +450,7 @@ impl Connection { /// let (response, mut body_reader) = recv_response.await?; /// let mut body = String::new(); /// body_reader.read_to_string(&mut body).await?; - /// + /// /// Ok(()) /// } /// ``` @@ -512,14 +512,14 @@ impl Connection { let recv = RecvResponse::new(FrameDecoder::stream(recv), self.0.clone(), stream_id); match body.into() { - Body::Buf(payload) => { + Body(Some(payload)) => { let send: WriteFrame> = WriteFrame::new(send, DataFrame { payload }); Ok(( recv, BodyWriter::new(send.await?, self.0.clone(), stream_id, false), )) } - Body::None => Ok(( + Body(None) => Ok(( recv, BodyWriter::new(send, self.0.clone(), stream_id, false), )), diff --git a/quinn-h3/src/server.rs b/quinn-h3/src/server.rs index 4294d83bb..de7657887 100644 --- a/quinn-h3/src/server.rs +++ b/quinn-h3/src/server.rs @@ -785,8 +785,8 @@ impl Sender { )? .await?; let send = match body.into() { - Body::None => send, - Body::Buf(payload) => WriteFrame::new(send, DataFrame { payload }).await?, + Body(None) => send, + Body(Some(payload)) => WriteFrame::new(send, DataFrame { payload }).await?, }; Ok(BodyWriter::new(send, self.conn, self.stream_id, true)) }