Skip to content

Commit 731e27a

Browse files
committed
Merge branch 'master' into run-examples
2 parents e30f184 + 3799be6 commit 731e27a

File tree

13 files changed

+75
-57
lines changed

13 files changed

+75
-57
lines changed

.travis.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,56 @@ language: rust
22
rust: nightly-2019-05-09
33
cache: cargo
44

5+
before_script:
6+
- >
7+
[[ "$(cargo-sweep --version)" == "cargo-sweep 0.4.1" ]]
8+
|| cargo install cargo-sweep
9+
- cargo sweep --stamp
10+
11+
before_cache:
12+
- cargo sweep --file
13+
514
matrix:
615
include:
716
- name: cargo doc
817
env: [CACHE_NAME=docs]
918
script:
10-
- RUSTDOCFLAGS=-Dwarnings
11-
cargo doc --all --all-features --no-deps --exclude tide
19+
- RUSTDOCFLAGS=-Dwarnings cargo doc
20+
-Zmtime-on-use
21+
--all --all-features
22+
--exclude tide
23+
--no-deps
1224

1325
- name: cargo fmt
1426
cache: false
15-
before_script: rustup component add rustfmt
16-
script: cargo fmt --all -- --check
27+
before_script: []
28+
install:
29+
- rustup component add rustfmt
30+
script:
31+
- cargo fmt --all -- --check
1732

1833
- name: cargo clippy
1934
env: [CACHE_NAME=clippy]
20-
before_script: rustup component add clippy
21-
script: cargo clippy --all --all-targets --exclude examples -- -Dwarnings
35+
install:
36+
- rustup component add clippy
37+
script:
38+
- cargo clippy
39+
-Zmtime-on-use
40+
--all --all-targets
41+
--exclude examples
42+
-- -Dwarnings
2243

2344
- name: cargo build --no-default-features
2445
env: [CACHE_NAME=no-default-features]
2546
script:
26-
- cargo build --no-default-features
27-
- cargo build --manifest-path tide-core/Cargo.toml --no-default-features
47+
- cargo build
48+
-Zmtime-on-use
49+
--manifest-path tide-core/Cargo.toml
50+
--no-default-features
51+
- cargo build
52+
-Zmtime-on-use
53+
--no-default-features
2854

2955
- name: cargo test
30-
script: cargo test --all --verbose
56+
script:
57+
- cargo test -Zmtime-on-use --all --verbose

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn main() -> Result<(), std::io::Error> {
7474
- [Hello World](https://github.com/rustasync/tide/blob/master/examples/src/hello.rs)
7575
- [Messages](https://github.com/rustasync/tide/blob/master/examples/src/messages.rs)
7676
- [Body Types](https://github.com/rustasync/tide/blob/master/examples/src/body_types.rs)
77-
- [Multipart Form](https://github.com/rustasync/tide/blob/master/examples/src/multipart-form/main.rs)
77+
- [Multipart Form](https://github.com/rustasync/tide/blob/master/examples/src/multipart_form/mod.rs)
7878
- [Catch All](https://github.com/rustasync/tide/blob/master/examples/src/catch_all.rs)
7979
- [Cookies](https://github.com/rustasync/tide/blob/master/examples/src/cookies.rs)
8080
- [Default Headers](https://github.com/rustasync/tide/blob/master/examples/src/default_headers.rs)

src/forms.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use futures::prelude::*;
12
use http_service::Body;
23
use multipart::server::Multipart;
34
use std::io::Cursor;
@@ -19,10 +20,12 @@ pub trait ContextExt {
1920
impl<State: Send + Sync + 'static> ContextExt for Context<State> {
2021
fn body_form<T: serde::de::DeserializeOwned>(&mut self) -> BoxTryFuture<T> {
2122
let body = self.take_body();
22-
box_async! {
23+
FutureExt::boxed(async move {
2324
let body = body.into_vec().await.client_err()?;
24-
Ok(serde_urlencoded::from_bytes(&body).map_err(|e| err_fmt!("could not decode form: {}", e)).client_err()?)
25-
}
25+
Ok(serde_urlencoded::from_bytes(&body)
26+
.map_err(|e| err_fmt!("could not decode form: {}", e))
27+
.client_err()?)
28+
})
2629
}
2730

2831
fn body_multipart(&mut self) -> BoxTryFuture<Multipart<Cursor<Vec<u8>>>> {
@@ -35,11 +38,13 @@ impl<State: Send + Sync + 'static> ContextExt for Context<State> {
3538

3639
let body = self.take_body();
3740

38-
box_async! {
41+
FutureExt::boxed(async move {
3942
let body = body.into_vec().await.client_err()?;
40-
let boundary = boundary.ok_or_else(|| err_fmt!("no boundary found")).client_err()?;
43+
let boundary = boundary
44+
.ok_or_else(|| err_fmt!("no boundary found"))
45+
.client_err()?;
4146
Ok(Multipart::with_body(Cursor::new(body), boundary))
42-
}
47+
})
4348
}
4449
}
4550

src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
#[doc(include = "../README.md")]
2323
const _README: () = ();
2424

25-
macro_rules! box_async {
26-
{$($t:tt)*} => {
27-
::futures::future::FutureExt::boxed(async move { $($t)* })
28-
};
29-
}
30-
3125
#[macro_use]
3226
extern crate tide_core;
3327

src/middleware/default_headers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use futures::future::BoxFuture;
2+
use futures::prelude::*;
23

34
use http::{
45
header::{HeaderValue, IntoHeaderName},
@@ -41,14 +42,14 @@ impl DefaultHeaders {
4142

4243
impl<Data: Send + Sync + 'static> Middleware<Data> for DefaultHeaders {
4344
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
44-
box_async! {
45+
FutureExt::boxed(async move {
4546
let mut res = next.run(cx).await;
4647

4748
let headers = res.headers_mut();
4849
for (key, value) in self.headers.iter() {
4950
headers.entry(key).unwrap().or_insert_with(|| value.clone());
5051
}
5152
res
52-
}
53+
})
5354
}
5455
}

src/middleware/logger.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use slog_async;
33
use slog_term;
44

55
use futures::future::BoxFuture;
6+
use futures::prelude::*;
67

78
use crate::{
89
middleware::{Middleware, Next},
@@ -37,14 +38,14 @@ impl Default for RootLogger {
3738
/// is generated.
3839
impl<Data: Send + Sync + 'static> Middleware<Data> for RootLogger {
3940
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
40-
box_async! {
41+
FutureExt::boxed(async move {
4142
let path = cx.uri().path().to_owned();
4243
let method = cx.method().as_str().to_owned();
4344

4445
let res = next.run(cx).await;
4546
let status = res.status();
4647
info!(self.inner_logger, "{} {} {}", method, path, status.as_str());
4748
res
48-
}
49+
})
4950
}
5051
}

tide-compression/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pub use accept_encoding::Encoding;
1414
use async_compression::stream;
1515
use futures::future::BoxFuture;
16+
use futures::prelude::*;
1617
use http::{header::CONTENT_ENCODING, status::StatusCode, HeaderMap};
1718
use http_service::{Body, Request};
1819
use tide::{
@@ -21,12 +22,6 @@ use tide::{
2122
Context, Error, Response,
2223
};
2324

24-
macro_rules! box_async {
25-
{$($t:tt)*} => {
26-
::futures::future::FutureExt::boxed(async move { $($t)* })
27-
};
28-
}
29-
3025
/// Encode settings for the compression middleware.
3126
///
3227
/// This can be modified in the case that you want more control over the speed or quality of compression.
@@ -137,14 +132,14 @@ impl Compression {
137132

138133
impl<Data: Send + Sync + 'static> Middleware<Data> for Compression {
139134
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
140-
box_async! {
135+
FutureExt::boxed(async move {
141136
let encoding = match self.preferred_encoding(cx.headers()) {
142137
Ok(encoding) => encoding,
143138
Err(e) => return e.into_response(),
144139
};
145140
let res = next.run(cx).await;
146141
self.encode(res, encoding)
147-
}
142+
})
148143
}
149144
}
150145

@@ -225,13 +220,13 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for Decompression {
225220
mut cx: Context<Data>,
226221
next: Next<'a, Data>,
227222
) -> BoxFuture<'a, Response> {
228-
box_async! {
223+
FutureExt::boxed(async move {
229224
match self.decode(cx.request_mut()) {
230225
Ok(_) => (),
231226
Err(e) => return e.into_response(),
232227
};
233228
next.run(cx).await
234-
}
229+
})
235230
}
236231
}
237232

tide-cookies/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
missing_debug_implementations
99
)]
1010

11-
#[macro_use]
12-
extern crate tide_core;
13-
1411
mod data;
1512
mod middleware;
1613

tide-cookies/src/middleware.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::data::CookieData;
22
use futures::future::BoxFuture;
3+
use futures::prelude::*;
34
use http::header::HeaderValue;
45

56
use tide_core::{
@@ -31,7 +32,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
3132
mut cx: Context<Data>,
3233
next: Next<'a, Data>,
3334
) -> BoxFuture<'a, Response> {
34-
box_async! {
35+
FutureExt::boxed(async move {
3536
let cookie_data = cx
3637
.extensions_mut()
3738
.remove()
@@ -56,7 +57,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
5657
}
5758
}
5859
res
59-
}
60+
})
6061
}
6162
}
6263

tide-core/src/app.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use futures::future::{self, BoxFuture};
2+
use futures::prelude::*;
23
use http_service::HttpService;
34
use std::sync::Arc;
45

@@ -292,7 +293,7 @@ impl<State: Sync + Send + 'static> HttpService for Server<State> {
292293
let middleware = self.middleware.clone();
293294
let data = self.data.clone();
294295

295-
box_async! {
296+
FutureExt::boxed(async move {
296297
let fut = {
297298
let Selection { endpoint, params } = router.route(&path, method);
298299
let cx = Context::new(data, req, params);
@@ -306,7 +307,7 @@ impl<State: Sync + Send + 'static> HttpService for Server<State> {
306307
};
307308

308309
Ok(fut.await)
309-
}
310+
})
310311
}
311312
}
312313

tide-core/src/endpoint.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use futures::future::{BoxFuture, Future};
2+
use futures::prelude::*;
23

34
use crate::{response::IntoResponse, Context, Response};
45

@@ -68,8 +69,6 @@ where
6869
type Fut = BoxFuture<'static, Response>;
6970
fn call(&self, cx: Context<State>) -> Self::Fut {
7071
let fut = (self)(cx);
71-
box_async! {
72-
fut.await.into_response()
73-
}
72+
FutureExt::boxed(async move { fut.await.into_response() })
7473
}
7574
}

tide-core/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111
// ISSUE: https://github.com/rust-lang/rust-clippy/issues/3988
1212
#![allow(clippy::needless_lifetimes)]
1313

14-
#[macro_export]
15-
macro_rules! box_async {
16-
{$($t:tt)*} => {
17-
::futures::future::FutureExt::boxed(async move { $($t)* })
18-
};
19-
}
20-
2114
mod app;
2215
mod context;
2316
mod endpoint;

tide-core/src/router.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use fnv::FnvHashMap;
2-
use futures::future::{BoxFuture, FutureExt};
2+
use futures::future::BoxFuture;
3+
use futures::prelude::*;
34
use http_service::Body;
45
use route_recognizer::{Match, Params, Router as MethodRouter};
56

@@ -62,7 +63,10 @@ impl<State: 'static> Router<State> {
6263
}
6364

6465
fn not_found_endpoint<Data>(_cx: Context<Data>) -> BoxFuture<'static, Response> {
65-
box_async! {
66-
http::Response::builder().status(http::StatusCode::NOT_FOUND).body(Body::empty()).unwrap()
67-
}
66+
FutureExt::boxed(async move {
67+
http::Response::builder()
68+
.status(http::StatusCode::NOT_FOUND)
69+
.body(Body::empty())
70+
.unwrap()
71+
})
6872
}

0 commit comments

Comments
 (0)