Skip to content

Commit 031454e

Browse files
authored
fest(body): rename HttpBody export to Body (#2969)
Now that the concrete `Body` type has been temporarily replaced with `Recv` in #2966, we can rename and export `http_body::Body` as just `Body` instead of `HttpBody`. Closes #2839 BREAKING CHANGE: The trait has been renamed.
1 parent d963e6a commit 031454e

23 files changed

+104
-104
lines changed

examples/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44

55
use bytes::Bytes;
66
use http_body_util::Empty;
7-
use hyper::{body::HttpBody as _, Request};
7+
use hyper::{body::Body as _, Request};
88
use tokio::io::{self, AsyncWriteExt as _};
99
use tokio::net::TcpStream;
1010

examples/echo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::net::SocketAddr;
44

55
use bytes::Bytes;
66
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
7-
use hyper::body::HttpBody as _;
7+
use hyper::body::Body as _;
88
use hyper::server::conn::Http;
99
use hyper::service::service_fn;
1010
use hyper::{Method, Recv, Request, Response, StatusCode};

examples/single_threaded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::net::SocketAddr;
66
use std::rc::Rc;
77
use tokio::net::TcpListener;
88

9-
use hyper::body::{Bytes, HttpBody};
9+
use hyper::body::{Body as HttpBody, Bytes};
1010
use hyper::header::{HeaderMap, HeaderValue};
1111
use hyper::service::service_fn;
1212
use hyper::{Error, Response};

src/body/aggregate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use bytes::Buf;
22

3-
use super::HttpBody;
3+
use super::Body;
44
use crate::common::buf::BufList;
55

66
/// Aggregate the data buffers from a body asynchronously.
77
///
8-
/// The returned `impl Buf` groups the `Buf`s from the `HttpBody` without
8+
/// The returned `impl Buf` groups the `Buf`s from the `Body` without
99
/// copying them. This is ideal if you don't require a contiguous buffer.
1010
///
1111
/// # Note
@@ -15,7 +15,7 @@ use crate::common::buf::BufList;
1515
/// `Content-Length` is a possibility, but it is not strictly mandated to be present.
1616
pub async fn aggregate<T>(body: T) -> Result<impl Buf, T::Error>
1717
where
18-
T: HttpBody,
18+
T: Body,
1919
{
2020
let mut bufs = BufList::new();
2121

src/body/body.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures_channel::mpsc;
55
use futures_channel::oneshot;
66
use futures_core::Stream; // for mpsc::Receiver
77
use http::HeaderMap;
8-
use http_body::{Body as HttpBody, SizeHint};
8+
use http_body::{Body, SizeHint};
99

1010
use super::DecodedLength;
1111
use crate::common::Future;
@@ -18,7 +18,7 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
1818

1919
/// A stream of `Bytes`, used when receiving bodies.
2020
///
21-
/// A good default [`HttpBody`](crate::body::HttpBody) to use in many
21+
/// A good default [`Body`](crate::body::Body) to use in many
2222
/// applications.
2323
///
2424
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes)
@@ -195,7 +195,7 @@ impl Recv {
195195
}
196196
}
197197

198-
impl HttpBody for Recv {
198+
impl Body for Recv {
199199
type Data = Bytes;
200200
type Error = crate::Error;
201201

@@ -386,7 +386,7 @@ mod tests {
386386
use std::mem;
387387
use std::task::Poll;
388388

389-
use super::{DecodedLength, HttpBody, Recv, Sender, SizeHint};
389+
use super::{Body, DecodedLength, Recv, Sender, SizeHint};
390390

391391
#[test]
392392
fn test_size_of() {
@@ -402,7 +402,7 @@ mod tests {
402402
body_expected_size,
403403
);
404404

405-
assert_eq!(body_size, mem::size_of::<Option<Recv>>(), "Option<Body>");
405+
assert_eq!(body_size, mem::size_of::<Option<Recv>>(), "Option<Recv>");
406406

407407
assert_eq!(
408408
mem::size_of::<Sender>(),

src/body/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
//!
88
//! There are two pieces to this in hyper:
99
//!
10-
//! - **The [`HttpBody`](HttpBody) trait** describes all possible bodies.
11-
//! hyper allows any body type that implements `HttpBody`, allowing
10+
//! - **The [`Body`](Body) trait** describes all possible bodies.
11+
//! hyper allows any body type that implements `Body`, allowing
1212
//! applications to have fine-grained control over their streaming.
1313
//! - **The [`Recv`](Recv) concrete type**, which is an implementation of
14-
//! `HttpBody`, and returned by hyper as a "receive stream" (so, for server
14+
//! `Body`, and returned by hyper as a "receive stream" (so, for server
1515
//! requests and client responses). It is also a decent default implementation
1616
//! if you don't have very custom needs of your send streams.
1717
1818
pub use bytes::{Buf, Bytes};
19-
pub use http_body::Body as HttpBody;
19+
pub use http_body::Body;
2020
pub use http_body::SizeHint;
2121

2222
pub use self::aggregate::aggregate;

src/body/to_bytes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytes::{Buf, BufMut, Bytes};
22

3-
use super::HttpBody;
3+
use super::Body;
44

55
/// Concatenate the buffers from a body into a single `Bytes` asynchronously.
66
///
@@ -19,7 +19,7 @@ use super::HttpBody;
1919
/// ```
2020
/// # use hyper::{Recv, Response};
2121
/// # async fn doc(response: Response<Recv>) -> hyper::Result<()> {
22-
/// # use hyper::body::HttpBody;
22+
/// # use hyper::body::Body;
2323
/// // let response: Response<Body> ...
2424
///
2525
/// const MAX_ALLOWED_RESPONSE_SIZE: u64 = 1024;
@@ -39,7 +39,7 @@ use super::HttpBody;
3939
/// ```
4040
pub async fn to_bytes<T>(body: T) -> Result<Bytes, T::Error>
4141
where
42-
T: HttpBody,
42+
T: Body,
4343
{
4444
futures_util::pin_mut!(body);
4545

src/client/conn/http1.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use httparse::ParserConfig;
99
use tokio::io::{AsyncRead, AsyncWrite};
1010

1111
use crate::Recv;
12-
use crate::body::HttpBody;
12+
use crate::body::Body;
1313
use crate::common::{
1414
exec::{BoxSendFuture, Exec},
1515
task, Future, Pin, Poll,
@@ -35,7 +35,7 @@ pub struct SendRequest<B> {
3535
pub struct Connection<T, B>
3636
where
3737
T: AsyncRead + AsyncWrite + Send + 'static,
38-
B: HttpBody + 'static,
38+
B: Body + 'static,
3939
{
4040
inner: Option<Dispatcher<T, B>>,
4141
}
@@ -102,7 +102,7 @@ impl<B> SendRequest<B> {
102102

103103
impl<B> SendRequest<B>
104104
where
105-
B: HttpBody + 'static,
105+
B: Body + 'static,
106106
{
107107
/// Sends a `Request` on the associated connection.
108108
///
@@ -180,7 +180,7 @@ impl<B> fmt::Debug for SendRequest<B> {
180180
impl<T, B> fmt::Debug for Connection<T, B>
181181
where
182182
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
183-
B: HttpBody + 'static,
183+
B: Body + 'static,
184184
{
185185
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
186186
f.debug_struct("Connection").finish()
@@ -190,7 +190,7 @@ where
190190
impl<T, B> Future for Connection<T, B>
191191
where
192192
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
193-
B: HttpBody + Send + 'static,
193+
B: Body + Send + 'static,
194194
B::Data: Send,
195195
B::Error: Into<Box<dyn StdError + Send + Sync>>,
196196
{
@@ -427,7 +427,7 @@ impl Builder {
427427
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
428428
where
429429
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
430-
B: HttpBody + 'static,
430+
B: Body + 'static,
431431
B::Data: Send,
432432
B::Error: Into<Box<dyn StdError + Send + Sync>>,
433433
{

src/client/conn/http2.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use http::{Request, Response};
1111
use tokio::io::{AsyncRead, AsyncWrite};
1212

1313
use crate::Recv;
14-
use crate::body::HttpBody;
14+
use crate::body::Body;
1515
use crate::common::{
1616
exec::{BoxSendFuture, Exec},
1717
task, Future, Pin, Poll,
@@ -33,7 +33,7 @@ pub struct SendRequest<B> {
3333
pub struct Connection<T, B>
3434
where
3535
T: AsyncRead + AsyncWrite + Send + 'static,
36-
B: HttpBody + 'static,
36+
B: Body + 'static,
3737
{
3838
inner: (PhantomData<T>, proto::h2::ClientTask<B>),
3939
}
@@ -96,7 +96,7 @@ impl<B> SendRequest<B> {
9696

9797
impl<B> SendRequest<B>
9898
where
99-
B: HttpBody + 'static,
99+
B: Body + 'static,
100100
{
101101
/// Sends a `Request` on the associated connection.
102102
///
@@ -174,7 +174,7 @@ impl<B> fmt::Debug for SendRequest<B> {
174174
impl<T, B> fmt::Debug for Connection<T, B>
175175
where
176176
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
177-
B: HttpBody + 'static,
177+
B: Body + 'static,
178178
{
179179
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
180180
f.debug_struct("Connection").finish()
@@ -184,7 +184,7 @@ where
184184
impl<T, B> Future for Connection<T, B>
185185
where
186186
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
187-
B: HttpBody + Send + 'static,
187+
B: Body + Send + 'static,
188188
B::Data: Send,
189189
B::Error: Into<Box<dyn StdError + Send + Sync>>,
190190
{
@@ -388,7 +388,7 @@ impl Builder {
388388
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
389389
where
390390
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
391-
B: HttpBody + 'static,
391+
B: Body + 'static,
392392
B::Data: Send,
393393
B::Error: Into<Box<dyn StdError + Send + Sync>>,
394394
{

src/client/conn/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use tower_service::Service;
7373
use tracing::{debug, trace};
7474

7575
use super::dispatch;
76-
use crate::body::HttpBody;
76+
use crate::body::Body;
7777
#[cfg(not(all(feature = "http1", feature = "http2")))]
7878
use crate::common::Never;
7979
use crate::common::{
@@ -108,7 +108,7 @@ pin_project! {
108108
#[project = ProtoClientProj]
109109
enum ProtoClient<T, B>
110110
where
111-
B: HttpBody,
111+
B: Body,
112112
{
113113
H1 {
114114
#[pin]
@@ -130,7 +130,7 @@ pub async fn handshake<T, B>(
130130
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
131131
where
132132
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
133-
B: HttpBody + 'static,
133+
B: Body + 'static,
134134
B::Data: Send,
135135
B::Error: Into<Box<dyn StdError + Send + Sync>>,
136136
{
@@ -150,7 +150,7 @@ pub struct SendRequest<B> {
150150
pub struct Connection<T, B>
151151
where
152152
T: AsyncRead + AsyncWrite + Send + 'static,
153-
B: HttpBody + 'static,
153+
B: Body + 'static,
154154
{
155155
inner: Option<ProtoClient<T, B>>,
156156
}
@@ -232,7 +232,7 @@ impl<B> SendRequest<B> {
232232

233233
impl<B> SendRequest<B>
234234
where
235-
B: HttpBody + 'static,
235+
B: Body + 'static,
236236
{
237237
/// Sends a `Request` on the associated connection.
238238
///
@@ -266,7 +266,7 @@ where
266266

267267
impl<B> Service<Request<B>> for SendRequest<B>
268268
where
269-
B: HttpBody + 'static,
269+
B: Body + 'static,
270270
{
271271
type Response = Response<Recv>;
272272
type Error = crate::Error;
@@ -292,7 +292,7 @@ impl<B> fmt::Debug for SendRequest<B> {
292292
impl<T, B> Connection<T, B>
293293
where
294294
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
295-
B: HttpBody + Unpin + Send + 'static,
295+
B: Body + Unpin + Send + 'static,
296296
B::Data: Send,
297297
B::Error: Into<Box<dyn StdError + Send + Sync>>,
298298
{
@@ -375,7 +375,7 @@ where
375375
impl<T, B> Future for Connection<T, B>
376376
where
377377
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
378-
B: HttpBody + Send + 'static,
378+
B: Body + Send + 'static,
379379
B::Data: Send,
380380
B::Error: Into<Box<dyn StdError + Send + Sync>>,
381381
{
@@ -403,7 +403,7 @@ where
403403
impl<T, B> fmt::Debug for Connection<T, B>
404404
where
405405
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
406-
B: HttpBody + 'static,
406+
B: Body + 'static,
407407
{
408408
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
409409
f.debug_struct("Connection").finish()
@@ -806,7 +806,7 @@ impl Builder {
806806
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
807807
where
808808
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
809-
B: HttpBody + 'static,
809+
B: Body + 'static,
810810
B::Data: Send,
811811
B::Error: Into<Box<dyn StdError + Send + Sync>>,
812812
{
@@ -905,7 +905,7 @@ impl fmt::Debug for ResponseFuture {
905905
impl<T, B> Future for ProtoClient<T, B>
906906
where
907907
T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
908-
B: HttpBody + Send + 'static,
908+
B: Body + Send + 'static,
909909
B::Data: Send,
910910
B::Error: Into<Box<dyn StdError + Send + Sync>>,
911911
{
@@ -938,7 +938,7 @@ impl<B: Send> AssertSendSync for SendRequest<B> {}
938938
impl<T: Send, B: Send> AssertSend for Connection<T, B>
939939
where
940940
T: AsyncRead + AsyncWrite + Send + 'static,
941-
B: HttpBody + 'static,
941+
B: Body + 'static,
942942
B::Data: Send,
943943
{
944944
}
@@ -947,7 +947,7 @@ where
947947
impl<T: Send + Sync, B: Send + Sync> AssertSendSync for Connection<T, B>
948948
where
949949
T: AsyncRead + AsyncWrite + Send + 'static,
950-
B: HttpBody + 'static,
950+
B: Body + 'static,
951951
B::Data: Send + Sync + 'static,
952952
{
953953
}

0 commit comments

Comments
 (0)