Skip to content

Commit 294c311

Browse files
authored
Merge pull request #35 from cramertj/strip-whitespace
Strip whitespace
2 parents fdcb177 + ae6e6fa commit 294c311

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/app.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use crate::{
1010
router::{Resource, Router},
1111
Request,
1212
extract::Extract,
13-
RouteMatch,
14-
Response,
13+
RouteMatch,
14+
Response,
1515
body::Body,
1616
Middleware,
1717
};
1818

1919
/// The top-level type for setting up a Tide application.
20-
///
20+
///
2121
/// Apps are equipped with a handle to their own state (`Data`), which is available to all endpoints.
2222
/// This is a "handle" because it must be `Clone`, and endpoints are invoked with a fresh clone.
2323
/// They also hold a top-level router.
@@ -57,7 +57,7 @@ impl<Data: Clone + Send + Sync + 'static> App<Data> {
5757
}
5858

5959
/// Start serving the app at the given address.
60-
///
60+
///
6161
/// Blocks the calling thread indefinitely.
6262
pub fn serve<A: std::net::ToSocketAddrs>(self, addr: A) {
6363
let server: Server<Data> = self.into_server();
@@ -66,7 +66,7 @@ impl<Data: Clone + Send + Sync + 'static> App<Data> {
6666
let addr = addr.to_socket_addrs().unwrap().next().unwrap();
6767

6868
let server = hyper::Server::bind(&addr).serve(move || {
69-
let res: Result<_, std::io::Error> = Ok(server.clone());
69+
let res: Result<_, std::io::Error> = Ok(server.clone());
7070
res
7171
}).compat().map(|_| {
7272
let res: Result<(), ()> = Ok(());
@@ -94,17 +94,17 @@ impl<Data: Clone + Send + Sync + 'static> Service for Server<Data> {
9494
let router = self.router.clone();
9595
let middleware = self.middleware.clone();
9696

97-
let mut req = req.map(Body::from);
97+
let mut req = req.map(Body::from);
9898
let path = req.uri().path().to_owned();
9999
let method = req.method().to_owned();
100100

101-
FutureObj::new(Box::new(async move {
102-
if let Some((endpoint, params)) = router.route(&path, &method) {
101+
FutureObj::new(Box::new(async move {
102+
if let Some((endpoint, params)) = router.route(&path, &method) {
103103
for m in middleware.iter() {
104104
match await!(m.request(&mut data, req, &params)) {
105105
Ok(new_req) => req = new_req,
106106
Err(resp) => return Ok(resp.map(Into::into)),
107-
}
107+
}
108108
}
109109

110110
let (head, mut resp) = await!(endpoint.call(data.clone(), req, params));
@@ -122,7 +122,7 @@ impl<Data: Clone + Send + Sync + 'static> Service for Server<Data> {
122122
}
123123

124124
/// An extractor for accessing app data.
125-
///
125+
///
126126
/// Endpoints can use `AppData<T>` to gain a handle to the data (of type `T`) originally injected into their app.
127127
pub struct AppData<T>(pub T);
128128

@@ -147,4 +147,4 @@ impl<T: Clone + Send + 'static> Extract<T> for AppData<T> {
147147
) -> Self::Fut {
148148
future::ok(AppData(data.clone()))
149149
}
150-
}
150+
}

src/body.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Types for working directly with the bodies of requests and responses.
2-
//!
2+
//!
33
//! This module includes types like `Json`, which can be used to automatically (de)serialize bodies
44
//! using `serde_json`.
55
@@ -10,9 +10,9 @@ use http::status::StatusCode;
1010
use crate::{Extract, IntoResponse, RouteMatch, Request, Response};
1111

1212
/// The raw contents of an http request or response.
13-
///
13+
///
1414
/// A body is a stream of `BodyChunk`s, which are essentially `Vec<u8>` values.
15-
/// Both `Body` and `BodyChunk` values can be easily created from standard byte buffer types,
15+
/// Both `Body` and `BodyChunk` values can be easily created from standard byte buffer types,
1616
/// using the `From` trait.
1717
pub struct Body {
1818
inner: BodyInner,
@@ -54,8 +54,8 @@ impl Body {
5454
}
5555

5656
/// Collect the full contents of the body into a vector.
57-
///
58-
/// This method is asynchronous because, in general, it requires reading an async
57+
///
58+
/// This method is asynchronous because, in general, it requires reading an async
5959
/// stream of `BodyChunk` values.
6060
pub async fn to_vec(&mut self) -> Result<Vec<u8>, Error> {
6161
match &mut self.inner {
@@ -113,7 +113,7 @@ impl Into<hyper::Body> for Body {
113113
}
114114

115115
/// A wrapper for json (de)serialization of bodies.
116-
///
116+
///
117117
/// This type is usable both as an extractor (argument to an endpoint) and as a response
118118
/// (return value from an endpoint).
119119
pub struct Json<T>(pub T);
@@ -128,9 +128,9 @@ impl<T: Send + serde::de::DeserializeOwned + 'static, S: 'static> Extract<S> for
128128
params: &RouteMatch<'_>,
129129
) -> Self::Fut {
130130
let mut body = std::mem::replace(req.body_mut(), Body::empty());
131-
FutureObj::new(Box::new(async move {
131+
FutureObj::new(Box::new(async move {
132132
fn mk_err<T>(_: T) -> Response { StatusCode::BAD_REQUEST.into_response() }
133-
let body = await!(body.to_vec()).map_err(mk_err)?;
133+
let body = await!(body.to_vec()).map_err(mk_err)?;
134134
let json: T = serde_json::from_slice(&body).map_err(mk_err)?;
135135
Ok(Json(json))
136136
}))
@@ -146,4 +146,4 @@ impl<T: 'static + Send + serde::Serialize> IntoResponse for Json<T> {
146146
.body(Body::from(serde_json::to_vec(&self.0).unwrap()))
147147
.unwrap()
148148
}
149-
}
149+
}

0 commit comments

Comments
 (0)