Skip to content

Commit aa90d1d

Browse files
authored
Move adapters to http-body-util (#56)
1 parent 6f722a1 commit aa90d1d

File tree

18 files changed

+149
-92
lines changed

18 files changed

+149
-92
lines changed

.github/workflows/CI.yml

+1-1
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

+3-34
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.5"
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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unreleased
2+
3+
- Initial release, split from http-body 0.4.5.

http-body-util/Cargo.toml

+35
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

+5-3
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#![deny(
2+
missing_debug_implementations,
3+
missing_docs,
4+
unreachable_pub,
5+
rustdoc::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+
mod limited;
19+
20+
use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
21+
pub use self::empty::Empty;
22+
pub use self::full::Full;
23+
pub use self::limited::{LengthLimitError, Limited};
24+
25+
/// An extension trait for [`http_body::Body`] adding various combinators and adapters
26+
pub trait BodyExt: http_body::Body {
27+
/// Maps this body's data value to a different value.
28+
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
29+
where
30+
Self: Sized,
31+
F: FnMut(Self::Data) -> B,
32+
B: bytes::Buf,
33+
{
34+
MapData::new(self, f)
35+
}
36+
37+
/// Maps this body's error value to a different value.
38+
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
39+
where
40+
Self: Sized,
41+
F: FnMut(Self::Error) -> E,
42+
{
43+
MapErr::new(self, f)
44+
}
45+
46+
/// Turn this body into a boxed trait object.
47+
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
48+
where
49+
Self: Sized + Send + Sync + 'static,
50+
{
51+
BoxBody::new(self)
52+
}
53+
54+
/// Turn this body into a boxed trait object that is !Sync.
55+
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
56+
where
57+
Self: Sized + Send + 'static,
58+
{
59+
UnsyncBoxBody::new(self)
60+
}
61+
}
62+
63+
impl<T: ?Sized> BodyExt for T where T: http_body::Body {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::{Body, SizeHint};
21
use bytes::Buf;
32
use http::HeaderMap;
3+
use http_body::{Body, SizeHint};
44
use pin_project_lite::pin_project;
55
use std::error::Error;
66
use std::fmt;
File renamed without changes.

http-body/Cargo.toml

+30
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.5"
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

+1-45
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
missing_debug_implementations,
44
missing_docs,
55
unreachable_pub,
6-
broken_intra_doc_links
6+
rustdoc::broken_intra_doc_links
77
)]
88
#![cfg_attr(test, deny(warnings))]
99

@@ -13,21 +13,12 @@
1313
//!
1414
//! [`Body`]: trait.Body.html
1515
16-
mod empty;
17-
mod full;
18-
mod limited;
1916
mod next;
2017
mod size_hint;
2118

22-
pub mod combinators;
23-
24-
pub use self::empty::Empty;
25-
pub use self::full::Full;
26-
pub use self::limited::{LengthLimitError, Limited};
2719
pub use self::next::{Data, Trailers};
2820
pub use self::size_hint::SizeHint;
2921

30-
use self::combinators::{BoxBody, MapData, MapErr, UnsyncBoxBody};
3122
use bytes::{Buf, Bytes};
3223
use http::HeaderMap;
3324
use std::convert::Infallible;
@@ -98,41 +89,6 @@ pub trait Body {
9889
{
9990
Trailers(self)
10091
}
101-
102-
/// Maps this body's data value to a different value.
103-
fn map_data<F, B>(self, f: F) -> MapData<Self, F>
104-
where
105-
Self: Sized,
106-
F: FnMut(Self::Data) -> B,
107-
B: Buf,
108-
{
109-
MapData::new(self, f)
110-
}
111-
112-
/// Maps this body's error value to a different value.
113-
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
114-
where
115-
Self: Sized,
116-
F: FnMut(Self::Error) -> E,
117-
{
118-
MapErr::new(self, f)
119-
}
120-
121-
/// Turn this body into a boxed trait object.
122-
fn boxed(self) -> BoxBody<Self::Data, Self::Error>
123-
where
124-
Self: Sized + Send + Sync + 'static,
125-
{
126-
BoxBody::new(self)
127-
}
128-
129-
/// Turn this body into a boxed trait object that is !Sync.
130-
fn boxed_unsync(self) -> UnsyncBoxBody<Self::Data, Self::Error>
131-
where
132-
Self: Sized + Send + 'static,
133-
{
134-
UnsyncBoxBody::new(self)
135-
}
13692
}
13793

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

tests/is_end_stream.rs renamed to http-body/tests/is_end_stream.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ fn is_end_stream_default_false() {
7070
size_hint: SizeHint::default(),
7171
};
7272

73-
assert_eq!(
74-
false,
75-
Pin::new(&mut mock).is_end_stream(),
73+
assert!(
74+
!Pin::new(&mut mock).is_end_stream(),
7675
"size_hint = {:?}",
7776
mock.size_hint.clone()
7877
);

0 commit comments

Comments
 (0)