Skip to content

Commit

Permalink
Move utilities and combinators to a separate package
Browse files Browse the repository at this point in the history
Hyper works with all combinators removed, as would anything that depends
on the initial 0.4 release.

Removing methods from the trait is a breaking change, but it is possible
to do the semver trick (release 0.5, then release 0.4.x with a
dependency on the 0.5 trait) to not split the ecosystem.

Addresses #52.
  • Loading branch information
g2p committed May 21, 2022
1 parent 6f722a1 commit 01d2211
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Run tests
run: cargo test
run: cargo test --workspace
37 changes: 3 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
[package]
name = "http-body"
# When releasing to crates.io:
# - Remove path dependencies
# - Update html_root_url.
# - Update doc url
# - Cargo.toml
# - README.md
# - Update CHANGELOG.md.
# - Create "vx.y.z" git tag.
version = "0.4.5"
authors = [
"Carl Lerche <me@carllerche.com>",
"Lucio Franco <luciofranco14@gmail.com>",
"Sean McArthur <sean@seanmonstar.com>",
]
edition = "2018"
readme = "README.md"
documentation = "https://docs.rs/http-body"
repository = "https://github.com/hyperium/http-body"
license = "MIT"
description = """
Trait representing an asynchronous, streaming, HTTP request or response body.
"""
keywords = ["http"]
categories = ["web-programming"]

[dependencies]
bytes = "1"
http = "0.2"
pin-project-lite = "0.2"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt"] }
[workspace]
members = ["http-body", "http-body-util"]
resolver = "2"
3 changes: 3 additions & 0 deletions http-body-util/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Unreleased

- Initial release, split from http-body 0.4.5.
35 changes: 35 additions & 0 deletions http-body-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "http-body-util"
# When releasing to crates.io:
# - Remove path dependencies
# - Update html_root_url.
# - Update doc url
# - Cargo.toml
# - README.md
# - Update CHANGELOG.md.
# - Create "http-body-util-x.y.z" git tag.
version = "0.1.0"
authors = [
"Carl Lerche <me@carllerche.com>",
"Lucio Franco <luciofranco14@gmail.com>",
"Sean McArthur <sean@seanmonstar.com>",
]
edition = "2018"
readme = "README.md"
documentation = "https://docs.rs/http-body-util"
repository = "https://github.com/hyperium/http-body"
license = "MIT"
description = """
Combinators and adapters for HTTP request or response bodies.
"""
keywords = ["http"]
categories = ["web-programming"]

[dependencies]
bytes = "1"
http = "0.2"
http-body = { path = "../http-body" }
pin-project-lite = "0.2"

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt"] }
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::Body;
use crate::BodyExt as _;

use bytes::Buf;
use http_body::{Body, SizeHint};
use std::{
fmt,
pin::Pin,
Expand Down Expand Up @@ -60,7 +62,7 @@ where
self.inner.is_end_stream()
}

fn size_hint(&self) -> crate::SizeHint {
fn size_hint(&self) -> SizeHint {
self.inner.size_hint()
}
}
Expand Down Expand Up @@ -119,7 +121,7 @@ where
self.inner.is_end_stream()
}

fn size_hint(&self) -> crate::SizeHint {
fn size_hint(&self) -> SizeHint {
self.inner.size_hint()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Body;
use bytes::Buf;
use http_body::Body;
use pin_project_lite::pin_project;
use std::{
any::type_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Body;
use http_body::{Body, SizeHint};
use pin_project_lite::pin_project;
use std::{
any::type_name,
Expand Down Expand Up @@ -79,7 +79,7 @@ where
self.inner.is_end_stream()
}

fn size_hint(&self) -> crate::SizeHint {
fn size_hint(&self) -> SizeHint {
self.inner.size_hint()
}
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/empty.rs → http-body-util/src/empty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Body, SizeHint};
use bytes::Buf;
use http::HeaderMap;
use http_body::{Body, SizeHint};
use std::{
convert::Infallible,
fmt,
Expand Down
2 changes: 1 addition & 1 deletion src/full.rs → http-body-util/src/full.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Body, SizeHint};
use bytes::{Buf, Bytes};
use http::HeaderMap;
use http_body::{Body, SizeHint};
use pin_project_lite::pin_project;
use std::borrow::Cow;
use std::convert::{Infallible, TryFrom};
Expand Down
63 changes: 63 additions & 0 deletions http-body-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#![deny(
missing_debug_implementations,
missing_docs,
unreachable_pub,
broken_intra_doc_links
)]
#![cfg_attr(test, deny(warnings))]

//! Utilities for [`http_body::Body`].
//!
//! [`BodyExt`] adds extensions to the common trait.
//!
//! [`Empty`] and [`Full`] provide simple implementations.

pub mod combinators;
mod empty;
mod full;
mod limited;

use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
pub use self::empty::Empty;
pub use self::full::Full;
pub use self::limited::{LengthLimitError, Limited};

/// An extension trait for [`http_body::Body`] adding various combinators and adapters
pub trait BodyExt: http_body::Body {
/// Maps this body's data value to a different value.
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
where
Self: Sized,
F: FnMut(Self::Data) -> B,
B: bytes::Buf,
{
MapData::new(self, f)
}

/// Maps this body's error value to a different value.
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where
Self: Sized,
F: FnMut(Self::Error) -> E,
{
MapErr::new(self, f)
}

/// Turn this body into a boxed trait object.
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
where
Self: Sized + Send + Sync + 'static,
{
BoxBody::new(self)
}

/// Turn this body into a boxed trait object that is !Sync.
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
where
Self: Sized + Send + 'static,
{
UnsyncBoxBody::new(self)
}
}

impl<T: ?Sized> BodyExt for T where T: http_body::Body {}
2 changes: 1 addition & 1 deletion src/limited.rs → http-body-util/src/limited.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Body, SizeHint};
use bytes::Buf;
use http::HeaderMap;
use http_body::{Body, SizeHint};
use pin_project_lite::pin_project;
use std::error::Error;
use std::fmt;
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions http-body/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "http-body"
# When releasing to crates.io:
# - Remove path dependencies
# - Update html_root_url.
# - Update doc url
# - Cargo.toml
# - README.md
# - Update CHANGELOG.md.
# - Create "http-body-x.y.z" git tag.
version = "0.4.5"
authors = [
"Carl Lerche <me@carllerche.com>",
"Lucio Franco <luciofranco14@gmail.com>",
"Sean McArthur <sean@seanmonstar.com>",
]
edition = "2018"
readme = "README.md"
documentation = "https://docs.rs/http-body"
repository = "https://github.com/hyperium/http-body"
license = "MIT"
description = """
Trait representing an asynchronous, streaming, HTTP request or response body.
"""
keywords = ["http"]
categories = ["web-programming"]

[dependencies]
bytes = "1"
http = "0.2"
44 changes: 0 additions & 44 deletions src/lib.rs → http-body/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@
//!
//! [`Body`]: trait.Body.html

mod empty;
mod full;
mod limited;
mod next;
mod size_hint;

pub mod combinators;

pub use self::empty::Empty;
pub use self::full::Full;
pub use self::limited::{LengthLimitError, Limited};
pub use self::next::{Data, Trailers};
pub use self::size_hint::SizeHint;

use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
use bytes::{Buf, Bytes};
use http::HeaderMap;
use std::convert::Infallible;
Expand Down Expand Up @@ -98,41 +89,6 @@ pub trait Body {
{
Trailers(self)
}

/// Maps this body's data value to a different value.
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
where
Self: Sized,
F: FnMut(Self::Data) -> B,
B: Buf,
{
MapData::new(self, f)
}

/// Maps this body's error value to a different value.
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where
Self: Sized,
F: FnMut(Self::Error) -> E,
{
MapErr::new(self, f)
}

/// Turn this body into a boxed trait object.
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
where
Self: Sized + Send + Sync + 'static,
{
BoxBody::new(self)
}

/// Turn this body into a boxed trait object that is !Sync.
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
where
Self: Sized + Send + 'static,
{
UnsyncBoxBody::new(self)
}
}

impl<T: Body + Unpin + ?Sized> Body for &mut T {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 01d2211

Please sign in to comment.