Skip to content

Commit

Permalink
fest(body): rename HttpBody export to Body (#2969)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RajivTS committed Aug 30, 2022
1 parent d963e6a commit 031454e
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 104 deletions.
2 changes: 1 addition & 1 deletion examples/client.rs
Expand Up @@ -4,7 +4,7 @@ use std::env;

use bytes::Bytes;
use http_body_util::Empty;
use hyper::{body::HttpBody as _, Request};
use hyper::{body::Body as _, Request};
use tokio::io::{self, AsyncWriteExt as _};
use tokio::net::TcpStream;

Expand Down
2 changes: 1 addition & 1 deletion examples/echo.rs
Expand Up @@ -4,7 +4,7 @@ use std::net::SocketAddr;

use bytes::Bytes;
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::body::HttpBody as _;
use hyper::body::Body as _;
use hyper::server::conn::Http;
use hyper::service::service_fn;
use hyper::{Method, Recv, Request, Response, StatusCode};
Expand Down
2 changes: 1 addition & 1 deletion examples/single_threaded.rs
Expand Up @@ -6,7 +6,7 @@ use std::net::SocketAddr;
use std::rc::Rc;
use tokio::net::TcpListener;

use hyper::body::{Bytes, HttpBody};
use hyper::body::{Body as HttpBody, Bytes};
use hyper::header::{HeaderMap, HeaderValue};
use hyper::service::service_fn;
use hyper::{Error, Response};
Expand Down
6 changes: 3 additions & 3 deletions src/body/aggregate.rs
@@ -1,11 +1,11 @@
use bytes::Buf;

use super::HttpBody;
use super::Body;
use crate::common::buf::BufList;

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

Expand Down
10 changes: 5 additions & 5 deletions src/body/body.rs
Expand Up @@ -5,7 +5,7 @@ use futures_channel::mpsc;
use futures_channel::oneshot;
use futures_core::Stream; // for mpsc::Receiver
use http::HeaderMap;
use http_body::{Body as HttpBody, SizeHint};
use http_body::{Body, SizeHint};

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

/// A stream of `Bytes`, used when receiving bodies.
///
/// A good default [`HttpBody`](crate::body::HttpBody) to use in many
/// A good default [`Body`](crate::body::Body) to use in many
/// applications.
///
/// Note: To read the full body, use [`body::to_bytes`](crate::body::to_bytes)
Expand Down Expand Up @@ -195,7 +195,7 @@ impl Recv {
}
}

impl HttpBody for Recv {
impl Body for Recv {
type Data = Bytes;
type Error = crate::Error;

Expand Down Expand Up @@ -386,7 +386,7 @@ mod tests {
use std::mem;
use std::task::Poll;

use super::{DecodedLength, HttpBody, Recv, Sender, SizeHint};
use super::{Body, DecodedLength, Recv, Sender, SizeHint};

#[test]
fn test_size_of() {
Expand All @@ -402,7 +402,7 @@ mod tests {
body_expected_size,
);

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

assert_eq!(
mem::size_of::<Sender>(),
Expand Down
8 changes: 4 additions & 4 deletions src/body/mod.rs
Expand Up @@ -7,16 +7,16 @@
//!
//! There are two pieces to this in hyper:
//!
//! - **The [`HttpBody`](HttpBody) trait** describes all possible bodies.
//! hyper allows any body type that implements `HttpBody`, allowing
//! - **The [`Body`](Body) trait** describes all possible bodies.
//! hyper allows any body type that implements `Body`, allowing
//! applications to have fine-grained control over their streaming.
//! - **The [`Recv`](Recv) concrete type**, which is an implementation of
//! `HttpBody`, and returned by hyper as a "receive stream" (so, for server
//! `Body`, and returned by hyper as a "receive stream" (so, for server
//! requests and client responses). It is also a decent default implementation
//! if you don't have very custom needs of your send streams.

pub use bytes::{Buf, Bytes};
pub use http_body::Body as HttpBody;
pub use http_body::Body;
pub use http_body::SizeHint;

pub use self::aggregate::aggregate;
Expand Down
6 changes: 3 additions & 3 deletions src/body/to_bytes.rs
@@ -1,6 +1,6 @@
use bytes::{Buf, BufMut, Bytes};

use super::HttpBody;
use super::Body;

/// Concatenate the buffers from a body into a single `Bytes` asynchronously.
///
Expand All @@ -19,7 +19,7 @@ use super::HttpBody;
/// ```
/// # use hyper::{Recv, Response};
/// # async fn doc(response: Response<Recv>) -> hyper::Result<()> {
/// # use hyper::body::HttpBody;
/// # use hyper::body::Body;
/// // let response: Response<Body> ...
///
/// const MAX_ALLOWED_RESPONSE_SIZE: u64 = 1024;
Expand All @@ -39,7 +39,7 @@ use super::HttpBody;
/// ```
pub async fn to_bytes<T>(body: T) -> Result<Bytes, T::Error>
where
T: HttpBody,
T: Body,
{
futures_util::pin_mut!(body);

Expand Down
12 changes: 6 additions & 6 deletions src/client/conn/http1.rs
Expand Up @@ -9,7 +9,7 @@ use httparse::ParserConfig;
use tokio::io::{AsyncRead, AsyncWrite};

use crate::Recv;
use crate::body::HttpBody;
use crate::body::Body;
use crate::common::{
exec::{BoxSendFuture, Exec},
task, Future, Pin, Poll,
Expand All @@ -35,7 +35,7 @@ pub struct SendRequest<B> {
pub struct Connection<T, B>
where
T: AsyncRead + AsyncWrite + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
inner: Option<Dispatcher<T, B>>,
}
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<B> SendRequest<B> {

impl<B> SendRequest<B>
where
B: HttpBody + 'static,
B: Body + 'static,
{
/// Sends a `Request` on the associated connection.
///
Expand Down Expand Up @@ -180,7 +180,7 @@ impl<B> fmt::Debug for SendRequest<B> {
impl<T, B> fmt::Debug for Connection<T, B>
where
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connection").finish()
Expand All @@ -190,7 +190,7 @@ where
impl<T, B> Future for Connection<T, B>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + Send + 'static,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -427,7 +427,7 @@ impl Builder {
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down
12 changes: 6 additions & 6 deletions src/client/conn/http2.rs
Expand Up @@ -11,7 +11,7 @@ use http::{Request, Response};
use tokio::io::{AsyncRead, AsyncWrite};

use crate::Recv;
use crate::body::HttpBody;
use crate::body::Body;
use crate::common::{
exec::{BoxSendFuture, Exec},
task, Future, Pin, Poll,
Expand All @@ -33,7 +33,7 @@ pub struct SendRequest<B> {
pub struct Connection<T, B>
where
T: AsyncRead + AsyncWrite + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
inner: (PhantomData<T>, proto::h2::ClientTask<B>),
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl<B> SendRequest<B> {

impl<B> SendRequest<B>
where
B: HttpBody + 'static,
B: Body + 'static,
{
/// Sends a `Request` on the associated connection.
///
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<B> fmt::Debug for SendRequest<B> {
impl<T, B> fmt::Debug for Connection<T, B>
where
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connection").finish()
Expand All @@ -184,7 +184,7 @@ where
impl<T, B> Future for Connection<T, B>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + Send + 'static,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -388,7 +388,7 @@ impl Builder {
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down
26 changes: 13 additions & 13 deletions src/client/conn/mod.rs
Expand Up @@ -73,7 +73,7 @@ use tower_service::Service;
use tracing::{debug, trace};

use super::dispatch;
use crate::body::HttpBody;
use crate::body::Body;
#[cfg(not(all(feature = "http1", feature = "http2")))]
use crate::common::Never;
use crate::common::{
Expand Down Expand Up @@ -108,7 +108,7 @@ pin_project! {
#[project = ProtoClientProj]
enum ProtoClient<T, B>
where
B: HttpBody,
B: Body,
{
H1 {
#[pin]
Expand All @@ -130,7 +130,7 @@ pub async fn handshake<T, B>(
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand All @@ -150,7 +150,7 @@ pub struct SendRequest<B> {
pub struct Connection<T, B>
where
T: AsyncRead + AsyncWrite + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
inner: Option<ProtoClient<T, B>>,
}
Expand Down Expand Up @@ -232,7 +232,7 @@ impl<B> SendRequest<B> {

impl<B> SendRequest<B>
where
B: HttpBody + 'static,
B: Body + 'static,
{
/// Sends a `Request` on the associated connection.
///
Expand Down Expand Up @@ -266,7 +266,7 @@ where

impl<B> Service<Request<B>> for SendRequest<B>
where
B: HttpBody + 'static,
B: Body + 'static,
{
type Response = Response<Recv>;
type Error = crate::Error;
Expand All @@ -292,7 +292,7 @@ impl<B> fmt::Debug for SendRequest<B> {
impl<T, B> Connection<T, B>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + Unpin + Send + 'static,
B: Body + Unpin + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -375,7 +375,7 @@ where
impl<T, B> Future for Connection<T, B>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + Send + 'static,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -403,7 +403,7 @@ where
impl<T, B> fmt::Debug for Connection<T, B>
where
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connection").finish()
Expand Down Expand Up @@ -806,7 +806,7 @@ impl Builder {
) -> impl Future<Output = crate::Result<(SendRequest<B>, Connection<T, B>)>>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -905,7 +905,7 @@ impl fmt::Debug for ResponseFuture {
impl<T, B> Future for ProtoClient<T, B>
where
T: AsyncRead + AsyncWrite + Send + Unpin + 'static,
B: HttpBody + Send + 'static,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
{
Expand Down Expand Up @@ -938,7 +938,7 @@ impl<B: Send> AssertSendSync for SendRequest<B> {}
impl<T: Send, B: Send> AssertSend for Connection<T, B>
where
T: AsyncRead + AsyncWrite + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send,
{
}
Expand All @@ -947,7 +947,7 @@ where
impl<T: Send + Sync, B: Send + Sync> AssertSendSync for Connection<T, B>
where
T: AsyncRead + AsyncWrite + Send + 'static,
B: HttpBody + 'static,
B: Body + 'static,
B::Data: Send + Sync + 'static,
{
}
Expand Down

0 comments on commit 031454e

Please sign in to comment.