Skip to content

Commit cac0824

Browse files
authored
Merge pull request #340 from http-rs/rewind-page-3
Rewind page 3
2 parents 8ba713c + 99cfe80 commit cac0824

File tree

17 files changed

+109
-120
lines changed

17 files changed

+109
-120
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: cargo fmt --all -- --check
7272

7373
- name: Docs
74-
run: cargo doc --features docs
74+
run: cargo doc
7575

7676
clippy_check:
7777
name: Clippy check

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added `logger::RequestLogger` based on `log` (replaces `logger:RootLogger`)
13+
14+
### Changed
15+
16+
- Resolved an `#[allow(unused_mut)]` workaround.
17+
- Renamed `ExtractForms` to `ContextExt`.
18+
19+
### Removed
20+
21+
- Removed `logger::RootLogger` (replaced by `logger:RequestLogger`)
22+
- Removed internal use of the `box_async` macro
23+
1024
## [0.3.0] - 2019-10-31
1125

1226
This is the first release in almost 6 months; introducing a snapshot of where we

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ route-recognizer = "0.1.13"
2929
serde = "1.0.102"
3030
serde_derive = "1.0.102"
3131
serde_json = "1.0.41"
32-
slog = "2.5.2"
33-
slog-async = "2.3.0"
34-
slog-term = "2.4.2"
3532
typemap = "0.3.3"
3633
serde_urlencoded = "0.6.1"
34+
log = "0.4.8"
3735

3836
[dependencies.http-service-hyper]
3937
optional = true

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
API Docs
3232
</a>
3333
<span> | </span>
34-
<a href="https://github.com/rustasync/tide/blob/master/.github/CONTRIBUTING.md">
34+
<a href="https://github.com/http-rs/tide/blob/master/.github/CONTRIBUTING.md">
3535
Contributing
3636
</a>
3737
<span> | </span>
@@ -60,23 +60,23 @@ fn main() -> Result<(), std::io::Error> {
6060

6161
**More Examples**
6262

63-
- [Hello World](https://github.com/rustasync/tide/tree/master/examples/hello.rs)
64-
- [Messages](https://github.com/rustasync/tide/blob/master/examples/messages.rs)
65-
- [Body Types](https://github.com/rustasync/tide/blob/master/examples/body_types.rs)
66-
- [Multipart Form](https://github.com/rustasync/tide/tree/master/examples/multipart-form/main.rs)
67-
- [Catch All](https://github.com/rustasync/tide/tree/master/examples/catch_all.rs)
68-
- [Cookies](https://github.com/rustasync/tide/tree/master/examples/cookies.rs)
69-
- [Default Headers](https://github.com/rustasync/tide/tree/master/examples/default_headers.rs)
70-
- [GraphQL](https://github.com/rustasync/tide/tree/master/examples/graphql.rs)
63+
- [Hello World](https://github.com/http-rs/tide/tree/master/examples/hello.rs)
64+
- [Messages](https://github.com/http-rs/tide/blob/master/examples/messages.rs)
65+
- [Body Types](https://github.com/http-rs/tide/blob/master/examples/body_types.rs)
66+
- [Multipart Form](https://github.com/http-rs/tide/tree/master/examples/multipart-form/main.rs)
67+
- [Catch All](https://github.com/http-rs/tide/tree/master/examples/catch_all.rs)
68+
- [Cookies](https://github.com/http-rs/tide/tree/master/examples/cookies.rs)
69+
- [Default Headers](https://github.com/http-rs/tide/tree/master/examples/default_headers.rs)
70+
- [GraphQL](https://github.com/http-rs/tide/tree/master/examples/graphql.rs)
7171

7272
## Resources
7373

7474
Read about the design here:
7575

76-
- [Rising Tide: building a modular web framework in the open](https://rustasync.github.io/team/2018/09/11/tide.html)
77-
- [Routing and extraction in Tide: a first sketch](https://rustasync.github.io/team/2018/10/16/tide-routing.html)
78-
- [Middleware in Tide](https://rustasync.github.io/team/2018/11/07/tide-middleware.html)
79-
- [Tide's evolving middleware approach](https://rustasync.github.io/team/2018/11/27/tide-middleware-evolution.html)
76+
- [Rising Tide: building a modular web framework in the open](https://http-rs.github.io/team/2018/09/11/tide.html)
77+
- [Routing and extraction in Tide: a first sketch](https://http-rs.github.io/team/2018/10/16/tide-routing.html)
78+
- [Middleware in Tide](https://http-rs.github.io/team/2018/11/07/tide-middleware.html)
79+
- [Tide's evolving middleware approach](https://http-rs.github.io/team/2018/11/27/tide-middleware-evolution.html)
8080

8181
## Contributing
8282

@@ -89,7 +89,7 @@ guide][contributing] and take a look at some of these issues:
8989
#### Conduct
9090

9191
The Tide project adheres to the [Contributor Covenant Code of
92-
Conduct](https://github.com/rustasync/tide/blob/master/.github/CODE_OF_CONDUCT.md). This
92+
Conduct](https://github.com/http-rs/tide/blob/master/.github/CODE_OF_CONDUCT.md). This
9393
describes the minimum behavior expected from all contributors.
9494

9595
## License
@@ -107,7 +107,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
107107
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
108108
dual licensed as above, without any additional terms or conditions.
109109

110-
[releases]: https://github.com/rustasync/tide/releases
111-
[contributing]: https://github.com/rustasync/tide/blob/master/.github/CONTRIBUTING.md
112-
[good-first-issue]: https://github.com/rustasync/tide/labels/good%20first%20issue
113-
[help-wanted]: https://github.com/rustasync/tide/labels/help%20wanted
110+
[releases]: https://github.com/http-rs/tide/releases
111+
[contributing]: https://github.com/http-rs/tide/blob/master/.github/CONTRIBUTING.md
112+
[good-first-issue]: https://github.com/http-rs/tide/labels/good%20first%20issue
113+
[help-wanted]: https://github.com/http-rs/tide/labels/help%20wanted

examples/body_types.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use tide::{
33
error::ResultExt,
4-
forms::{self, ExtractForms},
4+
forms::{self, ContextExt},
55
response, App, Context, EndpointResult,
66
};
77

@@ -11,28 +11,24 @@ struct Message {
1111
contents: String,
1212
}
1313

14-
#[allow(unused_mut)] // Workaround clippy bug
1514
async fn echo_string(mut cx: Context<()>) -> String {
1615
let msg = cx.body_string().await.unwrap();
1716
println!("String: {}", msg);
1817
msg
1918
}
2019

21-
#[allow(unused_mut)] // Workaround clippy bug
2220
async fn echo_bytes(mut cx: Context<()>) -> Vec<u8> {
2321
let msg = cx.body_bytes().await.unwrap();
2422
println!("Bytes: {:?}", msg);
2523
msg
2624
}
2725

28-
#[allow(unused_mut)] // Workaround clippy bug
2926
async fn echo_json(mut cx: Context<()>) -> EndpointResult {
3027
let msg = cx.body_json().await.client_err()?;
3128
println!("JSON: {:?}", msg);
3229
Ok(response::json(msg))
3330
}
3431

35-
#[allow(unused_mut)] // Workaround clippy bug
3632
async fn echo_form(mut cx: Context<()>) -> EndpointResult {
3733
let msg = cx.body_form().await?;
3834
println!("Form: {:?}", msg);

examples/cookies.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ async fn retrieve_cookie(mut cx: Context<()>) -> String {
77
format!("hello cookies: {:?}", cx.get_cookie("hello").unwrap())
88
}
99

10-
#[allow(unused_mut)] // Workaround clippy bug
1110
async fn set_cookie(mut cx: Context<()>) {
1211
cx.set_cookie(Cookie::new("hello", "world")).unwrap();
1312
}
1413

15-
#[allow(unused_mut)] // Workaround clippy bug
1614
async fn remove_cookie(mut cx: Context<()>) {
1715
cx.remove_cookie(Cookie::named("hello")).unwrap();
1816
}

examples/messages.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ impl Database {
3737
}
3838
}
3939

40-
#[allow(unused_mut)] // Workaround clippy bug
4140
async fn new_message(mut cx: Context<Database>) -> EndpointResult<String> {
4241
let msg = cx.body_json().await.client_err()?;
4342
Ok(cx.state().insert(msg).to_string())
4443
}
4544

46-
#[allow(unused_mut)] // Workaround clippy bug
4745
async fn set_message(mut cx: Context<Database>) -> EndpointResult<()> {
4846
let msg = cx.body_json().await.client_err()?;
4947
let id = cx.param("id").client_err()?;

examples/multipart-form/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::io::Read;
3-
use tide::{forms::ExtractForms, response, App, Context, EndpointResult};
3+
use tide::{forms::ContextExt, response, App, Context, EndpointResult};
44

55
#[derive(Serialize, Deserialize, Clone)]
66
struct Message {
@@ -9,7 +9,6 @@ struct Message {
99
file: Option<String>,
1010
}
1111

12-
#[allow(unused_mut)] // Workaround clippy bug
1312
async fn upload_file(mut cx: Context<()>) -> EndpointResult {
1413
// https://stackoverflow.com/questions/43424982/how-to-parse-multipart-forms-using-abonander-multipart-with-rocket
1514
let mut message = Message {

src/app.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::{
3333
///
3434
/// let mut app = tide::App::new();
3535
/// app.at("/hello").get(|_| async move {"Hello, world!"});
36-
/// app.serve("127.0.0.1:8000");
36+
/// app.serve("127.0.0.1:8000").unwrap();
3737
/// ```
3838
///
3939
/// # Routing and parameters
@@ -44,7 +44,6 @@ use crate::{
4444
/// segments as parameters to endpoints:
4545
///
4646
/// ```rust, no_run
47-
///
4847
/// use tide::error::ResultExt;
4948
///
5049
/// async fn hello(cx: tide::Context<()>) -> tide::EndpointResult<String> {
@@ -65,7 +64,7 @@ use crate::{
6564
/// "Use /hello/{your name} or /goodbye/{your name}"
6665
/// });
6766
///
68-
/// app.serve("127.0.0.1:8000");
67+
/// app.serve("127.0.0.1:8000").unwrap();
6968
/// ```
7069
///
7170
/// You can learn more about routing in the [`App::at`] documentation.
@@ -272,7 +271,7 @@ impl<State: Sync + Send + 'static> HttpService for Server<State> {
272271
let middleware = self.middleware.clone();
273272
let data = self.data.clone();
274273

275-
box_async! {
274+
Box::pin(async move {
276275
let fut = {
277276
let Selection { endpoint, params } = router.route(&path, method);
278277
let cx = Context::new(data, req, params);
@@ -286,7 +285,7 @@ impl<State: Sync + Send + 'static> HttpService for Server<State> {
286285
};
287286

288287
Ok(fut.await)
289-
}
288+
})
290289
}
291290
}
292291

src/endpoint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ where
6666
type Fut = BoxFuture<'static, Response>;
6767
fn call(&self, cx: Context<State>) -> Self::Fut {
6868
let fut = (self)(cx);
69-
box_async! {
70-
fut.await.into_response()
71-
}
69+
Box::pin(async move { fut.await.into_response() })
7270
}
7371
}

src/forms.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ use crate::{
88
};
99

1010
/// An extension trait for `Context`, providing form extraction.
11-
pub trait ExtractForms {
11+
pub trait ContextExt {
1212
/// Asynchronously extract the entire body as a single form.
1313
fn body_form<T: serde::de::DeserializeOwned>(&mut self) -> BoxTryFuture<T>;
1414

1515
/// Asynchronously extract the entire body as a multipart form.
1616
fn body_multipart(&mut self) -> BoxTryFuture<Multipart<Cursor<Vec<u8>>>>;
1717
}
1818

19-
impl<State: Send + Sync + 'static> ExtractForms for Context<State> {
19+
impl<State: Send + Sync + 'static> ContextExt for Context<State> {
2020
fn body_form<T: serde::de::DeserializeOwned>(&mut self) -> BoxTryFuture<T> {
2121
let body = self.take_body();
22-
box_async! {
22+
Box::pin(async move {
2323
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-
}
24+
Ok(serde_urlencoded::from_bytes(&body)
25+
.map_err(|e| err_fmt!("could not decode form: {}", e))
26+
.client_err()?)
27+
})
2628
}
2729

2830
fn body_multipart(&mut self) -> BoxTryFuture<Multipart<Cursor<Vec<u8>>>> {
@@ -35,11 +37,13 @@ impl<State: Send + Sync + 'static> ExtractForms for Context<State> {
3537

3638
let body = self.take_body();
3739

38-
box_async! {
40+
Box::pin(async move {
3941
let body = body.into_vec().await.client_err()?;
40-
let boundary = boundary.ok_or_else(|| err_fmt!("no boundary found")).client_err()?;
42+
let boundary = boundary
43+
.ok_or_else(|| err_fmt!("no boundary found"))
44+
.client_err()?;
4145
Ok(Multipart::with_body(Cursor::new(body), boundary))
42-
}
46+
})
4347
}
4448
}
4549

src/lib.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
#![cfg_attr(feature = "nightly", deny(missing_docs))]
2-
#![cfg_attr(feature = "nightly", feature(external_doc))]
3-
#![cfg_attr(feature = "nightly", doc(include = "../README.md"))]
4-
#![cfg_attr(test, deny(warnings))]
5-
#![allow(unused_variables)]
6-
#![deny(
7-
nonstandard_style,
8-
rust_2018_idioms,
9-
future_incompatible,
10-
missing_debug_implementations
11-
)]
12-
// TODO: Remove this after clippy bug due to async await is resolved.
13-
// ISSUE: https://github.com/rust-lang/rust-clippy/issues/3988
14-
#![allow(clippy::needless_lifetimes)]
1+
// #![warn(missing_docs)]
2+
#![warn(missing_debug_implementations, rust_2018_idioms)]
3+
#![allow(clippy::mutex_atomic, clippy::module_inception)]
4+
#![doc(test(attr(deny(rust_2018_idioms, warnings))))]
5+
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
156

16-
//!
177
//! Welcome to Tide.
188
//!
199
//! The [`App`](struct.App.html) docs are a good place to get started.
2010
//!
2111
//!
2212
23-
macro_rules! box_async {
24-
{$($t:tt)*} => {
25-
::futures::future::FutureExt::boxed(async move { $($t)* })
26-
};
27-
}
28-
2913
#[macro_use]
3014
pub mod error;
3115

src/middleware/cookies.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
3131
mut cx: Context<Data>,
3232
next: Next<'a, Data>,
3333
) -> BoxFuture<'a, Response> {
34-
box_async! {
34+
Box::pin(async move {
3535
let cookie_data = cx
3636
.extensions_mut()
3737
.remove()
@@ -56,7 +56,7 @@ impl<Data: Send + Sync + 'static> Middleware<Data> for CookiesMiddleware {
5656
}
5757
}
5858
res
59-
}
59+
})
6060
}
6161
}
6262

@@ -72,23 +72,19 @@ mod tests {
7272
static COOKIE_NAME: &str = "testCookie";
7373

7474
/// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter.
75-
#[allow(unused_mut)] // Workaround clippy bug
7675
async fn retrieve_cookie(mut cx: Context<()>) -> String {
7776
format!("{}", cx.get_cookie(COOKIE_NAME).unwrap().unwrap().value())
7877
}
7978

80-
#[allow(unused_mut)] // Workaround clippy bug
8179
async fn set_cookie(mut cx: Context<()>) {
8280
cx.set_cookie(Cookie::new(COOKIE_NAME, "NewCookieValue"))
8381
.unwrap();
8482
}
8583

86-
#[allow(unused_mut)] // Workaround clippy bug
8784
async fn remove_cookie(mut cx: Context<()>) {
8885
cx.remove_cookie(Cookie::named(COOKIE_NAME)).unwrap();
8986
}
9087

91-
#[allow(unused_mut)] // Workaround clippy bug
9288
async fn set_multiple_cookie(mut cx: Context<()>) {
9389
cx.set_cookie(Cookie::new("C1", "V1")).unwrap();
9490
cx.set_cookie(Cookie::new("C2", "V2")).unwrap();

src/middleware/default_headers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ impl DefaultHeaders {
4141

4242
impl<Data: Send + Sync + 'static> Middleware<Data> for DefaultHeaders {
4343
fn handle<'a>(&'a self, cx: Context<Data>, next: Next<'a, Data>) -> BoxFuture<'a, Response> {
44-
box_async! {
44+
Box::pin(async move {
4545
let mut res = next.run(cx).await;
4646

4747
let headers = res.headers_mut();
4848
for (key, value) in self.headers.iter() {
4949
headers.entry(key).unwrap().or_insert_with(|| value.clone());
5050
}
5151
res
52-
}
52+
})
5353
}
5454
}

0 commit comments

Comments
 (0)