Skip to content

Commit d87d812

Browse files
committed
Move utilities and combinators to a separate package
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.
1 parent a97da64 commit d87d812

File tree

17 files changed

+143
-85
lines changed

17 files changed

+143
-85
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- name: Install Rust
2828
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
2929
- name: Run tests
30-
run: cargo test
30+
run: cargo test --workspace

Cargo.toml

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
1-
[package]
2-
name = "http-body"
3-
# When releasing to crates.io:
4-
# - Remove path dependencies
5-
# - Update html_root_url.
6-
# - Update doc url
7-
# - Cargo.toml
8-
# - README.md
9-
# - Update CHANGELOG.md.
10-
# - Create "vx.y.z" git tag.
11-
version = "0.4.4"
12-
authors = [
13-
"Carl Lerche <[email protected]>",
14-
"Lucio Franco <[email protected]>",
15-
"Sean McArthur <[email protected]>",
16-
]
17-
edition = "2018"
18-
readme = "README.md"
19-
documentation = "https://docs.rs/http-body"
20-
repository = "https://github.com/hyperium/http-body"
21-
license = "MIT"
22-
description = """
23-
Trait representing an asynchronous, streaming, HTTP request or response body.
24-
"""
25-
keywords = ["http"]
26-
categories = ["web-programming"]
27-
28-
[dependencies]
29-
bytes = "1"
30-
http = "0.2"
31-
pin-project-lite = "0.2"
32-
33-
[dev-dependencies]
34-
tokio = { version = "1", features = ["macros", "rt"] }
1+
[workspace]
2+
members = ["http-body", "http-body-util"]
3+
resolver = "2"

http-body-util/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unreleased
2+
3+
- Initial release, split from http-body 0.4.4.

http-body-util/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[package]
2+
name = "http-body-util"
3+
# When releasing to crates.io:
4+
# - Remove path dependencies
5+
# - Update html_root_url.
6+
# - Update doc url
7+
# - Cargo.toml
8+
# - README.md
9+
# - Update CHANGELOG.md.
10+
# - Create "http-body-util-x.y.z" git tag.
11+
version = "0.1.0"
12+
authors = [
13+
"Carl Lerche <[email protected]>",
14+
"Lucio Franco <[email protected]>",
15+
"Sean McArthur <[email protected]>",
16+
]
17+
edition = "2018"
18+
readme = "README.md"
19+
documentation = "https://docs.rs/http-body-util"
20+
repository = "https://github.com/hyperium/http-body"
21+
license = "MIT"
22+
description = """
23+
Combinators and adapters for HTTP request or response bodies.
24+
"""
25+
keywords = ["http"]
26+
categories = ["web-programming"]
27+
28+
[dependencies]
29+
bytes = "1"
30+
http = "0.2"
31+
http-body = { path = "../http-body" }
32+
pin-project-lite = "0.2"
33+
34+
[dev-dependencies]
35+
tokio = { version = "1", features = ["macros", "rt"] }

src/combinators/box_body.rs renamed to http-body-util/src/combinators/box_body.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::Body;
1+
use crate::BodyExt as _;
2+
23
use bytes::Buf;
4+
use http_body::{Body, SizeHint};
35
use std::{
46
fmt,
57
pin::Pin,
@@ -60,7 +62,7 @@ where
6062
self.inner.is_end_stream()
6163
}
6264

63-
fn size_hint(&self) -> crate::SizeHint {
65+
fn size_hint(&self) -> SizeHint {
6466
self.inner.size_hint()
6567
}
6668
}
@@ -119,7 +121,7 @@ where
119121
self.inner.is_end_stream()
120122
}
121123

122-
fn size_hint(&self) -> crate::SizeHint {
124+
fn size_hint(&self) -> SizeHint {
123125
self.inner.size_hint()
124126
}
125127
}

src/combinators/map_data.rs renamed to http-body-util/src/combinators/map_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::Body;
21
use bytes::Buf;
2+
use http_body::Body;
33
use pin_project_lite::pin_project;
44
use std::{
55
any::type_name,

src/combinators/map_err.rs renamed to http-body-util/src/combinators/map_err.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::Body;
1+
use http_body::{Body, SizeHint};
22
use pin_project_lite::pin_project;
33
use std::{
44
any::type_name,
@@ -79,7 +79,7 @@ where
7979
self.inner.is_end_stream()
8080
}
8181

82-
fn size_hint(&self) -> crate::SizeHint {
82+
fn size_hint(&self) -> SizeHint {
8383
self.inner.size_hint()
8484
}
8585
}
File renamed without changes.

src/empty.rs renamed to http-body-util/src/empty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::{Body, SizeHint};
21
use bytes::Buf;
32
use http::HeaderMap;
3+
use http_body::{Body, SizeHint};
44
use std::{
55
convert::Infallible,
66
fmt,

src/full.rs renamed to http-body-util/src/full.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::{Body, SizeHint};
21
use bytes::{Buf, Bytes};
32
use http::HeaderMap;
3+
use http_body::{Body, SizeHint};
44
use pin_project_lite::pin_project;
55
use std::borrow::Cow;
66
use std::convert::{Infallible, TryFrom};

http-body-util/src/lib.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#![deny(
2+
missing_debug_implementations,
3+
missing_docs,
4+
unreachable_pub,
5+
broken_intra_doc_links
6+
)]
7+
#![cfg_attr(test, deny(warnings))]
8+
9+
//! Utilities for [`http_body::Body`].
10+
//!
11+
//! [`BodyExt`] adds extensions to the common trait.
12+
//!
13+
//! [`Empty`] and [`Full`] provide simple implementations.
14+
15+
pub mod combinators;
16+
mod empty;
17+
mod full;
18+
19+
use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
20+
pub use self::empty::Empty;
21+
pub use self::full::Full;
22+
23+
/// An extension trait for [`http_body::Body`] adding various combinators and adapters
24+
pub trait BodyExt: http_body::Body {
25+
/// Maps this body's data value to a different value.
26+
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
27+
where
28+
Self: Sized,
29+
F: FnMut(Self::Data) -> B,
30+
B: bytes::Buf,
31+
{
32+
MapData::new(self, f)
33+
}
34+
35+
/// Maps this body's error value to a different value.
36+
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
37+
where
38+
Self: Sized,
39+
F: FnMut(Self::Error) -> E,
40+
{
41+
MapErr::new(self, f)
42+
}
43+
44+
/// Turn this body into a boxed trait object.
45+
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
46+
where
47+
Self: Sized + Send + Sync + 'static,
48+
{
49+
BoxBody::new(self)
50+
}
51+
52+
/// Turn this body into a boxed trait object that is !Sync.
53+
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
54+
where
55+
Self: Sized + Send + 'static,
56+
{
57+
UnsyncBoxBody::new(self)
58+
}
59+
}
60+
61+
impl<T: ?Sized> BodyExt for T where T: http_body::Body {}
File renamed without changes.

http-body/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "http-body"
3+
# When releasing to crates.io:
4+
# - Remove path dependencies
5+
# - Update html_root_url.
6+
# - Update doc url
7+
# - Cargo.toml
8+
# - README.md
9+
# - Update CHANGELOG.md.
10+
# - Create "http-body-x.y.z" git tag.
11+
version = "0.4.4"
12+
authors = [
13+
"Carl Lerche <[email protected]>",
14+
"Lucio Franco <[email protected]>",
15+
"Sean McArthur <[email protected]>",
16+
]
17+
edition = "2018"
18+
readme = "README.md"
19+
documentation = "https://docs.rs/http-body"
20+
repository = "https://github.com/hyperium/http-body"
21+
license = "MIT"
22+
description = """
23+
Trait representing an asynchronous, streaming, HTTP request or response body.
24+
"""
25+
keywords = ["http"]
26+
categories = ["web-programming"]
27+
28+
[dependencies]
29+
bytes = "1"
30+
http = "0.2"

src/lib.rs renamed to http-body/src/lib.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,12 @@
1313
//!
1414
//! [`Body`]: trait.Body.html
1515
16-
mod empty;
17-
mod full;
1816
mod next;
1917
mod size_hint;
2018

21-
pub mod combinators;
22-
23-
pub use self::empty::Empty;
24-
pub use self::full::Full;
2519
pub use self::next::{Data, Trailers};
2620
pub use self::size_hint::SizeHint;
2721

28-
use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
2922
use bytes::Buf;
3023
use http::HeaderMap;
3124
use std::ops;
@@ -95,41 +88,6 @@ pub trait Body {
9588
{
9689
Trailers(self)
9790
}
98-
99-
/// Maps this body's data value to a different value.
100-
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
101-
where
102-
Self: Sized,
103-
F: FnMut(Self::Data) -> B,
104-
B: Buf,
105-
{
106-
MapData::new(self, f)
107-
}
108-
109-
/// Maps this body's error value to a different value.
110-
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
111-
where
112-
Self: Sized,
113-
F: FnMut(Self::Error) -> E,
114-
{
115-
MapErr::new(self, f)
116-
}
117-
118-
/// Turn this body into a boxed trait object.
119-
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
120-
where
121-
Self: Sized + Send + Sync + 'static,
122-
{
123-
BoxBody::new(self)
124-
}
125-
126-
/// Turn this body into a boxed trait object that is !Sync.
127-
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
128-
where
129-
Self: Sized + Send + 'static,
130-
{
131-
UnsyncBoxBody::new(self)
132-
}
13391
}
13492

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

0 commit comments

Comments
 (0)