Skip to content

Commit b0e67e3

Browse files
authored
Merge pull request #94 from fabricedesre/router-bump
Updating to recent rustc
2 parents 66add38 + bb32425 commit b0e67e3

File tree

6 files changed

+43
-56
lines changed

6 files changed

+43
-56
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: rust
22
rust:
3-
- nightly-2016-11-25
3+
- nightly-2017-03-02
44
script:
55
- RUST_BACKTRACE=1 cargo test

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ version = "0.1.0"
44
authors = ["Fernando Jiménez Moreno <[email protected]>", "Salvador de la Puente González <[email protected]"]
55

66
[dependencies]
7-
hyper = "0.9.10"
8-
iron = "0.4"
7+
hyper = "0.10"
8+
iron = "0.5"
99
iron-cors = { git = "https://github.com/fxbox/iron-cors.git" }
1010
jwt = "0.4.0"
1111
libc = "0.2.7"
1212
pwhash = "0.1.1"
13-
router = "0.4"
13+
router = "0.5"
1414
rustc-serialize = "0.3.18"
15-
rusqlite = "0.7"
15+
rusqlite = "0.10"
1616
rust-crypto = "0.2.34"
1717
unicase = "1.4.0"
18-
urlencoded = "0.4.0"
18+
urlencoded = "0.5"
1919
uuid = { version = "0.3", features = ["v4"] }
2020

2121
[dev-dependencies]
22-
iron-test = "0.4.0"
22+
iron-test = "0.5"
2323
stainless = "0.1.4"
2424
clippy = "0.0"
2525
url="1.2.0"

src/errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pub fn from_decoder_error(error: json::DecoderError) -> IronResult<Response> {
5959
match error {
6060
json::DecoderError::MissingFieldError(field) => {
6161
match field.as_ref() {
62-
"name" => from_user_builder_error(UserBuilderError::Name),
63-
"email" => from_user_builder_error(UserBuilderError::Email),
64-
"password" => from_user_builder_error(UserBuilderError::Password),
62+
"name" => from_user_builder_error(&UserBuilderError::Name),
63+
"email" => from_user_builder_error(&UserBuilderError::Email),
64+
"password" => from_user_builder_error(&UserBuilderError::Password),
6565
_ => EndpointError::with(status::BadRequest, 400,
6666
Some("Missing field".to_owned()))
6767

@@ -91,9 +91,9 @@ pub fn from_sqlite_error(error: rusqlite_error) -> IronResult<Response> {
9191
}
9292
}
9393

94-
pub fn from_user_builder_error(error: UserBuilderError)
94+
pub fn from_user_builder_error(error: &UserBuilderError)
9595
-> IronResult<Response> {
96-
let (errno, message) = match error {
96+
let (errno, message) = match *error {
9797
UserBuilderError::Name => {
9898
(100, Some("Invalid user name".to_owned()))
9999
},

src/invitation_middleware.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use hyper::header::{Connection, Headers};
99
use iron::AfterMiddleware;
1010
use iron::method::Method;
1111
use iron::prelude::*;
12-
use iron::response::ResponseBody;
1312
use rustc_serialize::json::{self, DecodeResult};
1413

1514
#[derive(Debug, RustcEncodable)]
@@ -94,22 +93,19 @@ impl AfterMiddleware for InvitationMiddleware {
9493
return Ok(res);
9594
}
9695

96+
// Extract the body's payload.
9797
let mut payload = Vec::new();
9898
{
99-
let mut response_body = ResponseBody::new(&mut payload);
100-
match res.body {
101-
Some(ref mut body) => body.write_body(&mut response_body).ok(),
102-
None => None,
103-
};
99+
if let Some(ref mut body) = res.body {
100+
body.write_body(&mut payload).ok();
101+
}
104102
}
105103
let payload = String::from_utf8(payload).unwrap();
106104
let payload: DecodeResult<CreateUserResponse> = json::decode(&payload);
107-
match payload {
108-
Ok(payload) => {
109-
self.send(&payload.email, &payload.activation_url);
110-
Ok(res)
111-
}
112-
Err(_) => Ok(res),
105+
if let Ok(payload) = payload {
106+
self.send(&payload.email, &payload.activation_url);
113107
}
108+
109+
Ok(res)
114110
}
115111
}

src/lib.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* This Source Code Form is subject to the terms of the Mozilla Public
2-
* License, v. 2.0. If a copy of the MPL was not distributed with this
3-
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
#![feature(associated_consts, plugin)]
66

@@ -34,28 +34,28 @@ mod invitation_middleware;
3434
mod users_db;
3535
mod users_router;
3636

37-
pub use users_db::UsersDb as UsersDb;
38-
pub use users_db::UserBuilder as UserBuilder;
39-
pub use users_db::UserBuilderError as UserBuilderError;
40-
pub use users_db::ReadFilter as ReadFilter;
41-
pub use users_db::User as User;
42-
pub use users_router::UsersRouter as UsersRouter;
43-
pub use auth_middleware::AuthMiddleware as AuthMiddleware;
44-
pub use auth_middleware::AuthEndpoint as AuthEndpoint;
45-
pub use auth_middleware::SessionToken as SessionToken;
37+
pub use users_db::UsersDb;
38+
pub use users_db::UserBuilder;
39+
pub use users_db::UserBuilderError;
40+
pub use users_db::ReadFilter;
41+
pub use users_db::User;
42+
pub use users_router::UsersRouter;
43+
pub use auth_middleware::AuthMiddleware;
44+
pub use auth_middleware::AuthEndpoint;
45+
pub use auth_middleware::SessionToken;
4646

4747
pub struct UsersManager {
4848
db_file_path: String,
49-
router: UsersRouter
49+
router: UsersRouter,
5050
}
5151

5252
impl UsersManager {
5353
/// Create the UsersManager.
5454
/// The database will be stored at `db_file_path`.
55-
pub fn new(db_file_path: &str)-> Self {
55+
pub fn new(db_file_path: &str) -> Self {
5656
UsersManager {
5757
db_file_path: String::from(db_file_path),
58-
router: UsersRouter::new(db_file_path)
58+
router: UsersRouter::new(db_file_path),
5959
}
6060
}
6161

@@ -76,12 +76,10 @@ impl UsersManager {
7676
pub fn setup_invitation_middleware(&mut self,
7777
email_server: &str,
7878
invitation_url_prepath: &str) {
79-
self.router.setup_invitation_middleware(email_server,
80-
invitation_url_prepath);
79+
self.router.setup_invitation_middleware(email_server, invitation_url_prepath);
8180
}
8281

83-
pub fn get_middleware(&self, auth_endpoints: Vec<AuthEndpoint>)
84-
-> AuthMiddleware {
82+
pub fn get_middleware(&self, auth_endpoints: Vec<AuthEndpoint>) -> AuthMiddleware {
8583
AuthMiddleware::new(auth_endpoints, self.db_file_path.to_owned())
8684
}
8785

src/users_router.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ macro_rules! get_user_id_from_request {
8484
Some("Missing user id".to_owned()));
8585
}
8686

87-
let user_id: String = match user_id.parse() {
88-
Ok(user_id) => user_id,
89-
Err(_) => return EndpointError::with(
90-
status::BadRequest, 400, Some("Invalid user id".to_owned())
91-
)
92-
};
93-
9487
$user_id = user_id;
9588
}
9689
}
@@ -168,7 +161,7 @@ impl UsersRouter {
168161
Ok(user) => user,
169162
Err(user_with_error) => {
170163
println!("{:?}", user_with_error);
171-
return from_user_builder_error(user_with_error.error);
164+
return from_user_builder_error(&user_with_error.error);
172165
}
173166
};
174167

@@ -244,7 +237,7 @@ impl UsersRouter {
244237
Ok(user) => user,
245238
Err(user_with_error) => {
246239
println!("{:?}", user_with_error);
247-
return from_user_builder_error(user_with_error.error);
240+
return from_user_builder_error(&user_with_error.error);
248241
}
249242
};
250243

@@ -415,11 +408,11 @@ impl UsersRouter {
415408
Ok(user) => user,
416409
Err(user_with_error) => {
417410
println!("{:?}", user_with_error);
418-
return from_user_builder_error(user_with_error.error);
411+
return from_user_builder_error(&user_with_error.error);
419412
}
420413
};
421414
match db.update(&user) {
422-
Ok(_) => Ok(Response::with((status::NoContent))),
415+
Ok(_) => Ok(Response::with(status::NoContent)),
423416
Err(error) => {
424417
println!("{:?}", error);
425418
from_sqlite_error(error)
@@ -480,7 +473,7 @@ impl UsersRouter {
480473
Ok(user) => user,
481474
Err(user_with_error) => {
482475
println!("{:?}", user_with_error);
483-
return from_user_builder_error(user_with_error.error);
476+
return from_user_builder_error(&user_with_error.error);
484477
}
485478
};
486479
match db.update(&user) {
@@ -557,7 +550,7 @@ impl UsersRouter {
557550

558551
if !users[0].id.is_empty() {
559552
match db.delete(&users[0].id) {
560-
Ok(_) => Ok(Response::with((status::NoContent))),
553+
Ok(_) => Ok(Response::with(status::NoContent)),
561554
Err(error) => {
562555
println!("{:?}", error);
563556
from_sqlite_error(error)

0 commit comments

Comments
 (0)