Skip to content

Commit

Permalink
clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Apr 29, 2018
1 parent d98d723 commit c72d138
Show file tree
Hide file tree
Showing 62 changed files with 1,743 additions and 819 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ cache:

matrix:
include:
- rust: 1.22.1
- rust: stable
- rust: beta
- rust: nightly
allow_failures:
- rust: 1.21.0
- rust: nightly

env:
Expand Down
4 changes: 1 addition & 3 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
max_width = 89
reorder_imports = true
#reorder_imports_in_group = true
#reorder_imported_names = true
wrap_comments = true
fn_args_density = "Compressed"
use_small_heuristics = false
#use_small_heuristics = false
126 changes: 97 additions & 29 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ impl<S: 'static> HttpHandler for HttpApplication<S> {
let mut req = req.with_state(Rc::clone(&self.state), self.router.clone());
let tp = self.get_handler(&mut req);
let inner = Rc::clone(&self.inner);
Ok(Box::new(Pipeline::new(req, Rc::clone(&self.middlewares), inner, tp)))
Ok(Box::new(Pipeline::new(
req,
Rc::clone(&self.middlewares),
inner,
tp,
)))
} else {
Err(req)
}
Expand Down Expand Up @@ -449,14 +454,20 @@ where
}
let parts = self.parts.as_mut().expect("Use after finish");

parts.handlers.push((path, Box::new(WrapHandler::new(handler))));
parts
.handlers
.push((path, Box::new(WrapHandler::new(handler))));
}
self
}

/// Register a middleware.
pub fn middleware<M: Middleware<S>>(mut self, mw: M) -> App<S> {
self.parts.as_mut().expect("Use after finish").middlewares.push(Box::new(mw));
self.parts
.as_mut()
.expect("Use after finish")
.middlewares
.push(Box::new(mw));
self
}

Expand Down Expand Up @@ -611,23 +622,30 @@ mod tests {

#[test]
fn test_default_resource() {
let mut app =
App::new().resource("/test", |r| r.f(|_| HttpResponse::Ok())).finish();
let mut app = App::new()
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
.finish();

let req = TestRequest::with_uri("/test").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::OK);

let req = TestRequest::with_uri("/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let mut app = App::new()
.default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed()))
.finish();
let req = TestRequest::with_uri("/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::METHOD_NOT_ALLOWED);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::METHOD_NOT_ALLOWED
);
}

#[test]
Expand All @@ -641,8 +659,9 @@ mod tests {

#[test]
fn test_state() {
let mut app =
App::with_state(10).resource("/", |r| r.f(|_| HttpResponse::Ok())).finish();
let mut app = App::with_state(10)
.resource("/", |r| r.f(|_| HttpResponse::Ok()))
.finish();
let req =
HttpRequest::default().with_state(Rc::clone(&app.state), app.router.clone());
let resp = app.run(req);
Expand Down Expand Up @@ -674,7 +693,9 @@ mod tests {

#[test]
fn test_handler() {
let mut app = App::new().handler("/test", |_| HttpResponse::Ok()).finish();
let mut app = App::new()
.handler("/test", |_| HttpResponse::Ok())
.finish();

let req = TestRequest::with_uri("/test").finish();
let resp = app.run(req);
Expand All @@ -690,16 +711,24 @@ mod tests {

let req = TestRequest::with_uri("/testapp").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let req = TestRequest::with_uri("/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);
}

#[test]
fn test_handler2() {
let mut app = App::new().handler("test", |_| HttpResponse::Ok()).finish();
let mut app = App::new()
.handler("test", |_| HttpResponse::Ok())
.finish();

let req = TestRequest::with_uri("/test").finish();
let resp = app.run(req);
Expand All @@ -715,11 +744,17 @@ mod tests {

let req = TestRequest::with_uri("/testapp").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let req = TestRequest::with_uri("/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);
}

#[test]
Expand All @@ -743,41 +778,68 @@ mod tests {

let req = TestRequest::with_uri("/prefix/testapp").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let req = TestRequest::with_uri("/prefix/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);
}

#[test]
fn test_route() {
let mut app = App::new()
.route("/test", Method::GET, |_: HttpRequest| HttpResponse::Ok())
.route("/test", Method::POST, |_: HttpRequest| HttpResponse::Created())
.route("/test", Method::GET, |_: HttpRequest| {
HttpResponse::Ok()
})
.route("/test", Method::POST, |_: HttpRequest| {
HttpResponse::Created()
})
.finish();

let req = TestRequest::with_uri("/test").method(Method::GET).finish();
let req = TestRequest::with_uri("/test")
.method(Method::GET)
.finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::OK);

let req = TestRequest::with_uri("/test").method(Method::POST).finish();
let req = TestRequest::with_uri("/test")
.method(Method::POST)
.finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::CREATED);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::CREATED
);

let req = TestRequest::with_uri("/test").method(Method::HEAD).finish();
let req = TestRequest::with_uri("/test")
.method(Method::HEAD)
.finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);
}

#[test]
fn test_handler_prefix() {
let mut app =
App::new().prefix("/app").handler("/test", |_| HttpResponse::Ok()).finish();
let mut app = App::new()
.prefix("/app")
.handler("/test", |_| HttpResponse::Ok())
.finish();

let req = TestRequest::with_uri("/test").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let req = TestRequest::with_uri("/app/test").finish();
let resp = app.run(req);
Expand All @@ -793,10 +855,16 @@ mod tests {

let req = TestRequest::with_uri("/app/testapp").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);

let req = TestRequest::with_uri("/app/blah").finish();
let resp = app.run(req);
assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND);
assert_eq!(
resp.as_response().unwrap().status(),
StatusCode::NOT_FOUND
);
}
}
4 changes: 3 additions & 1 deletion src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ impl Responder for Binary {
type Error = Error;

fn respond_to(self, _: HttpRequest) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().content_type("application/octet-stream").body(self))
Ok(HttpResponse::Ok()
.content_type("application/octet-stream")
.body(self))
}
}

Expand Down
35 changes: 22 additions & 13 deletions src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ pub struct Pause {
impl Pause {
/// Create message with pause duration parameter
pub fn new(time: Duration) -> Pause {
Pause {
time: Some(time),
}
Pause { time: Some(time) }
}
}

impl Default for Pause {
fn default() -> Pause {
Pause {
time: None,
}
Pause { time: None }
}
}

Expand Down Expand Up @@ -431,7 +427,8 @@ impl ClientConnector {
} else {
0
};
self.acquired_per_host.insert(key.clone(), per_host + 1);
self.acquired_per_host
.insert(key.clone(), per_host + 1);
}

fn release_key(&mut self, key: &Key) {
Expand All @@ -442,7 +439,8 @@ impl ClientConnector {
return;
};
if per_host > 1 {
self.acquired_per_host.insert(key.clone(), per_host - 1);
self.acquired_per_host
.insert(key.clone(), per_host - 1);
} else {
self.acquired_per_host.remove(key);
}
Expand Down Expand Up @@ -518,7 +516,9 @@ impl ClientConnector {
fn collect_periodic(&mut self, ctx: &mut Context<Self>) {
self.collect(true);
// re-schedule next collect period
ctx.run_later(Duration::from_secs(1), |act, ctx| act.collect_periodic(ctx));
ctx.run_later(Duration::from_secs(1), |act, ctx| {
act.collect_periodic(ctx)
});

// send stats
let stats = mem::replace(&mut self.stats, ClientConnectorStats::default());
Expand Down Expand Up @@ -583,7 +583,10 @@ impl ClientConnector {
wait,
conn_timeout,
};
self.waiters.entry(key).or_insert_with(VecDeque::new).push_back(waiter);
self.waiters
.entry(key)
.or_insert_with(VecDeque::new)
.push_back(waiter);
rx
}
}
Expand Down Expand Up @@ -828,7 +831,7 @@ impl fut::ActorFuture for Maintenance {
act.collect_waiters();

// check waiters
let tmp: &mut ClientConnector = unsafe { mem::transmute(act as &mut _) };
let tmp: &mut ClientConnector = unsafe { &mut *(act as *mut _) };

for (key, waiters) in &mut tmp.waiters {
while let Some(waiter) = waiters.pop_front() {
Expand Down Expand Up @@ -1102,15 +1105,21 @@ impl Pool {
if self.to_close.borrow().is_empty() {
None
} else {
Some(mem::replace(&mut *self.to_close.borrow_mut(), Vec::new()))
Some(mem::replace(
&mut *self.to_close.borrow_mut(),
Vec::new(),
))
}
}

fn collect_release(&self) -> Option<Vec<Connection>> {
if self.to_release.borrow().is_empty() {
None
} else {
Some(mem::replace(&mut *self.to_release.borrow_mut(), Vec::new()))
Some(mem::replace(
&mut *self.to_release.borrow_mut(),
Vec::new(),
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl HttpResponseParser {
let (len, version, status, headers_len) = {
let b = unsafe {
let b: &[u8] = buf;
mem::transmute(b)
&*(b as *const _)
};
let mut resp = httparse::Response::new(&mut headers);
match resp.parse(b)? {
Expand Down
Loading

0 comments on commit c72d138

Please sign in to comment.