From d9f989a49616658878dfb3e9f37d52608e134e2a Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Wed, 12 Jun 2019 19:41:29 -0700 Subject: [PATCH] Migrate all examples to Rust 2018. --- examples/config/Cargo.toml | 1 + examples/config/src/main.rs | 2 -- examples/config/tests/common/mod.rs | 6 +++--- examples/content_types/Cargo.toml | 1 + examples/content_types/src/main.rs | 3 +-- examples/content_types/src/tests.rs | 2 -- examples/cookies/Cargo.toml | 1 + examples/cookies/src/main.rs | 5 ++--- examples/errors/Cargo.toml | 1 + examples/errors/src/main.rs | 2 +- examples/errors/src/tests.rs | 1 - examples/fairings/Cargo.toml | 1 + examples/fairings/src/main.rs | 6 +++--- examples/form_kitchen_sink/Cargo.toml | 1 + examples/form_kitchen_sink/src/main.rs | 2 +- examples/form_kitchen_sink/src/tests.rs | 8 ++++---- examples/form_validation/Cargo.toml | 1 + examples/form_validation/src/main.rs | 2 +- examples/handlebars_templates/Cargo.toml | 1 + examples/handlebars_templates/src/main.rs | 13 ++++++------- examples/handlebars_templates/src/tests.rs | 12 ++++++------ examples/hello_2018/Cargo.toml | 2 +- examples/hello_person/Cargo.toml | 1 + examples/hello_person/src/tests.rs | 1 - examples/hello_world/Cargo.toml | 1 + examples/hello_world/src/tests.rs | 1 - examples/json/Cargo.toml | 1 + examples/json/src/main.rs | 6 +++--- examples/json/src/tests.rs | 2 +- examples/managed_queue/Cargo.toml | 1 + examples/managed_queue/src/main.rs | 5 ++--- examples/manual_routes/Cargo.toml | 1 + examples/msgpack/Cargo.toml | 1 + examples/msgpack/src/main.rs | 3 +-- examples/msgpack/src/tests.rs | 2 +- examples/optional_redirect/Cargo.toml | 1 + examples/optional_redirect/src/tests.rs | 1 - examples/pastebin/Cargo.toml | 1 + examples/pastebin/src/main.rs | 5 ++--- examples/pastebin/src/paste_id.rs | 2 +- examples/query_params/Cargo.toml | 1 + examples/query_params/src/tests.rs | 20 ++++++++++---------- examples/ranking/Cargo.toml | 1 + examples/ranking/src/tests.rs | 1 - examples/raw_sqlite/Cargo.toml | 1 + examples/raw_sqlite/src/main.rs | 4 ++-- examples/raw_upload/Cargo.toml | 1 + examples/redirect/Cargo.toml | 1 + examples/redirect/src/tests.rs | 1 - examples/request_guard/Cargo.toml | 1 + examples/request_local_state/Cargo.toml | 1 + examples/request_local_state/src/main.rs | 2 +- examples/session/Cargo.toml | 1 + examples/session/src/main.rs | 7 +++---- examples/session/src/tests.rs | 2 +- examples/state/Cargo.toml | 1 + examples/state/src/main.rs | 4 ++-- examples/static_files/Cargo.toml | 1 + examples/stream/Cargo.toml | 1 + examples/tera_templates/Cargo.toml | 1 + examples/tera_templates/src/main.rs | 4 +--- examples/tera_templates/src/tests.rs | 12 ++++++------ examples/testing/Cargo.toml | 1 + examples/tls/Cargo.toml | 1 + examples/tls/src/tests.rs | 1 - examples/todo/Cargo.toml | 1 + examples/todo/src/main.rs | 4 ++-- examples/todo/src/tests.rs | 8 +++----- examples/uuid/Cargo.toml | 1 + examples/uuid/src/main.rs | 2 -- 70 files changed, 103 insertions(+), 95 deletions(-) diff --git a/examples/config/Cargo.toml b/examples/config/Cargo.toml index be32ccdf..553a2f53 100644 --- a/examples/config/Cargo.toml +++ b/examples/config/Cargo.toml @@ -2,6 +2,7 @@ name = "config" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/config/src/main.rs b/examples/config/src/main.rs index b3719a5e..114a6b33 100644 --- a/examples/config/src/main.rs +++ b/examples/config/src/main.rs @@ -1,5 +1,3 @@ -extern crate rocket; - // This example's illustration is the Rocket.toml file. fn main() { rocket::ignite().launch(); diff --git a/examples/config/tests/common/mod.rs b/examples/config/tests/common/mod.rs index 85356361..7e51b6e1 100644 --- a/examples/config/tests/common/mod.rs +++ b/examples/config/tests/common/mod.rs @@ -7,8 +7,8 @@ use rocket::local::Client; struct LocalConfig(Config); #[get("/check_config")] -fn check_config(config: State) -> Option<()> { - let environment = match ::std::env::var("ROCKET_ENV") { +fn check_config(config: State<'_, LocalConfig>) -> Option<()> { + let environment = match std::env::var("ROCKET_ENV") { Ok(name) => name, Err(_) => return None }; @@ -52,7 +52,7 @@ fn check_config(config: State) -> Option<()> { pub fn test_config(environment: Environment) { // Manually set the config environment variable. Rocket will initialize the // environment in `ignite()`. We'll read this back in the handler to config. - ::std::env::set_var("ROCKET_ENV", environment.to_string()); + std::env::set_var("ROCKET_ENV", environment.to_string()); let rocket = rocket::ignite() .attach(AdHoc::on_attach("Local Config", |rocket| { diff --git a/examples/content_types/Cargo.toml b/examples/content_types/Cargo.toml index 699ed84f..d2d05996 100644 --- a/examples/content_types/Cargo.toml +++ b/examples/content_types/Cargo.toml @@ -2,6 +2,7 @@ name = "content_types" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/content_types/src/main.rs b/examples/content_types/src/main.rs index fe957a71..d62ce5d7 100644 --- a/examples/content_types/src/main.rs +++ b/examples/content_types/src/main.rs @@ -2,7 +2,6 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate serde_derive; -extern crate serde_json; #[cfg(test)] mod tests; @@ -42,7 +41,7 @@ fn post_hello(age: u8, name_data: Data) -> io::Result> { } #[catch(404)] -fn not_found(request: &Request) -> content::Html { +fn not_found(request: &Request<'_>) -> content::Html { let html = match request.format() { Some(ref mt) if !mt.is_json() && !mt.is_plain() => { format!("

'{}' requests are not supported.

", mt) diff --git a/examples/content_types/src/tests.rs b/examples/content_types/src/tests.rs index a6865af1..afe31228 100644 --- a/examples/content_types/src/tests.rs +++ b/examples/content_types/src/tests.rs @@ -1,5 +1,3 @@ -use super::rocket; -use super::serde_json; use super::Person; use rocket::http::{Accept, ContentType, Header, MediaType, Method, Status}; use rocket::local::Client; diff --git a/examples/cookies/Cargo.toml b/examples/cookies/Cargo.toml index 142a0273..bcf93e33 100644 --- a/examples/cookies/Cargo.toml +++ b/examples/cookies/Cargo.toml @@ -2,6 +2,7 @@ name = "cookies" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/cookies/src/main.rs b/examples/cookies/src/main.rs index eb884b93..3c4871f7 100644 --- a/examples/cookies/src/main.rs +++ b/examples/cookies/src/main.rs @@ -1,7 +1,6 @@ #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; -extern crate rocket_contrib; #[cfg(test)] mod tests; @@ -19,13 +18,13 @@ struct Message { } #[post("/submit", data = "")] -fn submit(mut cookies: Cookies, message: Form) -> Redirect { +fn submit(mut cookies: Cookies<'_>, message: Form) -> Redirect { cookies.add(Cookie::new("message", message.into_inner().message)); Redirect::to("/") } #[get("/")] -fn index(cookies: Cookies) -> Template { +fn index(cookies: Cookies<'_>) -> Template { let cookie = cookies.get("message"); let mut context = HashMap::new(); if let Some(ref cookie) = cookie { diff --git a/examples/errors/Cargo.toml b/examples/errors/Cargo.toml index eab8ece4..5e6bd16b 100644 --- a/examples/errors/Cargo.toml +++ b/examples/errors/Cargo.toml @@ -2,6 +2,7 @@ name = "errors" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/errors/src/main.rs b/examples/errors/src/main.rs index 9693363d..1004d397 100644 --- a/examples/errors/src/main.rs +++ b/examples/errors/src/main.rs @@ -12,7 +12,7 @@ fn hello(name: String, age: i8) -> String { } #[catch(404)] -fn not_found(req: &rocket::Request) -> content::Html { +fn not_found(req: &rocket::Request<'_>) -> content::Html { content::Html(format!("

Sorry, but '{}' is not a valid path!

Try visiting /hello/<name>/<age> instead.

", req.uri())) diff --git a/examples/errors/src/tests.rs b/examples/errors/src/tests.rs index 827bc0c6..78f41422 100644 --- a/examples/errors/src/tests.rs +++ b/examples/errors/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; use rocket::http::Status; diff --git a/examples/fairings/Cargo.toml b/examples/fairings/Cargo.toml index 28af205a..ae927777 100644 --- a/examples/fairings/Cargo.toml +++ b/examples/fairings/Cargo.toml @@ -2,6 +2,7 @@ name = "fairings" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/fairings/src/main.rs b/examples/fairings/src/main.rs index 0f1c982f..cd823e21 100644 --- a/examples/fairings/src/main.rs +++ b/examples/fairings/src/main.rs @@ -27,7 +27,7 @@ impl Fairing for Counter { } } - fn on_request(&self, request: &mut Request, _: &Data) { + fn on_request(&self, request: &mut Request<'_>, _: &Data) { if request.method() == Method::Get { self.get.fetch_add(1, Ordering::Relaxed); } else if request.method() == Method::Post { @@ -35,7 +35,7 @@ impl Fairing for Counter { } } - fn on_response(&self, request: &Request, response: &mut Response) { + fn on_response(&self, request: &Request<'_>, response: &mut Response<'_>) { if response.status() != Status::NotFound { return } @@ -58,7 +58,7 @@ fn hello() -> &'static str { } #[get("/token")] -fn token(token: State) -> String { +fn token(token: State<'_, Token>) -> String { format!("{}", token.0) } diff --git a/examples/form_kitchen_sink/Cargo.toml b/examples/form_kitchen_sink/Cargo.toml index db7f290a..c1f999a4 100644 --- a/examples/form_kitchen_sink/Cargo.toml +++ b/examples/form_kitchen_sink/Cargo.toml @@ -2,6 +2,7 @@ name = "form_kitchen_sink" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/form_kitchen_sink/src/main.rs b/examples/form_kitchen_sink/src/main.rs index 6c017e34..f3330af7 100644 --- a/examples/form_kitchen_sink/src/main.rs +++ b/examples/form_kitchen_sink/src/main.rs @@ -28,7 +28,7 @@ struct FormInput<'r> { } #[post("/", data = "")] -fn sink(sink: Result, FormError>) -> String { +fn sink(sink: Result>, FormError<'_>>) -> String { match sink { Ok(form) => format!("{:?}", &*form), Err(FormDataError::Io(_)) => format!("Form input was invalid UTF-8."), diff --git a/examples/form_kitchen_sink/src/tests.rs b/examples/form_kitchen_sink/src/tests.rs index 6c5d4f4a..cafbe685 100644 --- a/examples/form_kitchen_sink/src/tests.rs +++ b/examples/form_kitchen_sink/src/tests.rs @@ -5,7 +5,7 @@ use rocket::local::Client; use rocket::http::ContentType; impl fmt::Display for FormOption { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { FormOption::A => write!(f, "a"), FormOption::B => write!(f, "b"), @@ -23,14 +23,14 @@ fn assert_form_eq(client: &Client, form_str: &str, expected: String) { assert_eq!(res.body_string(), Some(expected)); } -fn assert_valid_form(client: &Client, input: &FormInput) { +fn assert_valid_form(client: &Client, input: &FormInput<'_>) { let f = format!("checkbox={}&number={}&type={}&password={}&textarea={}&select={}", input.checkbox, input.number, input.radio, input.password, input.text_area, input.select); assert_form_eq(client, &f, format!("{:?}", input)); } -fn assert_valid_raw_form(client: &Client, form_str: &str, input: &FormInput) { +fn assert_valid_raw_form(client: &Client, form_str: &str, input: &FormInput<'_>) { assert_form_eq(client, form_str, format!("{:?}", input)); } @@ -176,7 +176,7 @@ fn check_structurally_invalid_forms() { fn check_bad_utf8() { let client = Client::new(rocket()).unwrap(); unsafe { - let bad_str = ::std::str::from_utf8_unchecked(b"a=\xff"); + let bad_str = std::str::from_utf8_unchecked(b"a=\xff"); assert_form_eq(&client, bad_str, "Form input was invalid UTF-8.".into()); } } diff --git a/examples/form_validation/Cargo.toml b/examples/form_validation/Cargo.toml index ed433095..ffd3f687 100644 --- a/examples/form_validation/Cargo.toml +++ b/examples/form_validation/Cargo.toml @@ -2,6 +2,7 @@ name = "form_validation" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/form_validation/src/main.rs b/examples/form_validation/src/main.rs index 580e8170..e389004a 100644 --- a/examples/form_validation/src/main.rs +++ b/examples/form_validation/src/main.rs @@ -51,7 +51,7 @@ impl<'v> FromFormValue<'v> for AdultAge { } #[post("/login", data = "")] -fn login(user: Form) -> Result { +fn login(user: Form>) -> Result { if let Err(e) = user.age { return Err(format!("Age is invalid: {}", e)); } diff --git a/examples/handlebars_templates/Cargo.toml b/examples/handlebars_templates/Cargo.toml index b29c4197..cacf6f14 100644 --- a/examples/handlebars_templates/Cargo.toml +++ b/examples/handlebars_templates/Cargo.toml @@ -2,6 +2,7 @@ name = "handlebars_templates" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/handlebars_templates/src/main.rs b/examples/handlebars_templates/src/main.rs index 759674d6..5dcac211 100644 --- a/examples/handlebars_templates/src/main.rs +++ b/examples/handlebars_templates/src/main.rs @@ -2,7 +2,6 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate serde_derive; -extern crate rocket_contrib; #[cfg(test)] mod tests; @@ -10,8 +9,6 @@ use rocket::Request; use rocket::response::Redirect; use rocket_contrib::templates::{Template, handlebars}; -use handlebars::{Helper, Handlebars, Context, RenderContext, Output, HelperResult, JsonRender}; - #[derive(Serialize)] struct TemplateContext { title: &'static str, @@ -47,18 +44,20 @@ fn about() -> Template { } #[catch(404)] -fn not_found(req: &Request) -> Template { +fn not_found(req: &Request<'_>) -> Template { let mut map = std::collections::HashMap::new(); map.insert("path", req.uri().path()); Template::render("error/404", &map) } +use self::handlebars::{Helper, Handlebars, Context, RenderContext, Output, HelperResult, JsonRender}; + fn wow_helper( - h: &Helper, + h: &Helper<'_, '_>, _: &Handlebars, _: &Context, - _: &mut RenderContext, - out: &mut Output + _: &mut RenderContext<'_>, + out: &mut dyn Output ) -> HelperResult { if let Some(param) = h.param(0) { out.write("")?; diff --git a/examples/handlebars_templates/src/tests.rs b/examples/handlebars_templates/src/tests.rs index bc54a82a..89d159f9 100644 --- a/examples/handlebars_templates/src/tests.rs +++ b/examples/handlebars_templates/src/tests.rs @@ -16,7 +16,7 @@ macro_rules! dispatch { fn test_root() { // Check that the redirect works. for method in &[Get, Head] { - dispatch!(*method, "/", |_: &Client, mut response: LocalResponse| { + dispatch!(*method, "/", |_: &Client, mut response: LocalResponse<'_>| { assert_eq!(response.status(), Status::SeeOther); assert!(response.body().is_none()); @@ -27,8 +27,8 @@ fn test_root() { // Check that other request methods are not accepted (and instead caught). for method in &[Post, Put, Delete, Options, Trace, Connect, Patch] { - dispatch!(*method, "/", |client: &Client, mut response: LocalResponse| { - let mut map = ::std::collections::HashMap::new(); + dispatch!(*method, "/", |client: &Client, mut response: LocalResponse<'_>| { + let mut map = std::collections::HashMap::new(); map.insert("path", "/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); @@ -41,7 +41,7 @@ fn test_root() { #[test] fn test_name() { // Check that the /hello/ route works. - dispatch!(Get, "/hello/Jack%20Daniels", |client: &Client, mut response: LocalResponse| { + dispatch!(Get, "/hello/Jack%20Daniels", |client: &Client, mut response: LocalResponse<'_>| { let context = TemplateContext { title: "Hello", name: Some("Jack Daniels".into()), @@ -58,8 +58,8 @@ fn test_name() { #[test] fn test_404() { // Check that the error catcher works. - dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse| { - let mut map = ::std::collections::HashMap::new(); + dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse<'_>| { + let mut map = std::collections::HashMap::new(); map.insert("path", "/hello/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); diff --git a/examples/hello_2018/Cargo.toml b/examples/hello_2018/Cargo.toml index 06ae3682..23dee942 100644 --- a/examples/hello_2018/Cargo.toml +++ b/examples/hello_2018/Cargo.toml @@ -2,8 +2,8 @@ name = "hello_2018" version = "0.0.0" workspace = "../../" -publish = false edition = "2018" +publish = false [dependencies] rocket = { path = "../../core/lib" } diff --git a/examples/hello_person/Cargo.toml b/examples/hello_person/Cargo.toml index 76423aaa..99be046f 100644 --- a/examples/hello_person/Cargo.toml +++ b/examples/hello_person/Cargo.toml @@ -2,6 +2,7 @@ name = "hello_person" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/hello_person/src/tests.rs b/examples/hello_person/src/tests.rs index e6cd50e2..35fd3999 100644 --- a/examples/hello_person/src/tests.rs +++ b/examples/hello_person/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; use rocket::http::Status; diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index 8feb601e..2c03cf22 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -2,6 +2,7 @@ name = "hello_world" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/hello_world/src/tests.rs b/examples/hello_world/src/tests.rs index da0b732b..80bf4aeb 100644 --- a/examples/hello_world/src/tests.rs +++ b/examples/hello_world/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; #[test] diff --git a/examples/json/Cargo.toml b/examples/json/Cargo.toml index 570405f6..9605667a 100644 --- a/examples/json/Cargo.toml +++ b/examples/json/Cargo.toml @@ -2,6 +2,7 @@ name = "json" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index f2f6cc17..d2823dae 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -26,7 +26,7 @@ struct Message { // TODO: This example can be improved by using `route` with multiple HTTP verbs. #[post("/", format = "json", data = "")] -fn new(id: ID, message: Json, map: State) -> JsonValue { +fn new(id: ID, message: Json, map: State<'_, MessageMap>) -> JsonValue { let mut hashmap = map.lock().expect("map lock."); if hashmap.contains_key(&id) { json!({ @@ -40,7 +40,7 @@ fn new(id: ID, message: Json, map: State) -> JsonValue { } #[put("/", format = "json", data = "")] -fn update(id: ID, message: Json, map: State) -> Option { +fn update(id: ID, message: Json, map: State<'_, MessageMap>) -> Option { let mut hashmap = map.lock().unwrap(); if hashmap.contains_key(&id) { hashmap.insert(id, message.0.contents); @@ -51,7 +51,7 @@ fn update(id: ID, message: Json, map: State) -> Option", format = "json")] -fn get(id: ID, map: State) -> Option> { +fn get(id: ID, map: State<'_, MessageMap>) -> Option> { let hashmap = map.lock().unwrap(); hashmap.get(&id).map(|contents| { Json(Message { diff --git a/examples/json/src/tests.rs b/examples/json/src/tests.rs index 8d22448b..8b690937 100644 --- a/examples/json/src/tests.rs +++ b/examples/json/src/tests.rs @@ -1,4 +1,4 @@ -use rocket; +use crate::rocket; use rocket::local::Client; use rocket::http::{Status, ContentType}; diff --git a/examples/managed_queue/Cargo.toml b/examples/managed_queue/Cargo.toml index c2041ac3..ba8330e9 100644 --- a/examples/managed_queue/Cargo.toml +++ b/examples/managed_queue/Cargo.toml @@ -2,6 +2,7 @@ name = "managed_queue" version = "0.0.0" workspace = "../.." +edition = "2018" publish = false [dependencies] diff --git a/examples/managed_queue/src/main.rs b/examples/managed_queue/src/main.rs index 809dd353..22ed3db1 100644 --- a/examples/managed_queue/src/main.rs +++ b/examples/managed_queue/src/main.rs @@ -1,7 +1,6 @@ #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; -extern crate crossbeam; #[cfg(test)] mod tests; @@ -11,12 +10,12 @@ use crossbeam::queue::SegQueue; struct LogChannel(SegQueue); #[put("/push?")] -fn push(event: String, queue: State) { +fn push(event: String, queue: State<'_, LogChannel>) { queue.0.push(event); } #[get("/pop")] -fn pop(queue: State) -> Option { +fn pop(queue: State<'_, LogChannel>) -> Option { queue.0.pop().ok() } diff --git a/examples/manual_routes/Cargo.toml b/examples/manual_routes/Cargo.toml index ba5399a8..8519ae94 100644 --- a/examples/manual_routes/Cargo.toml +++ b/examples/manual_routes/Cargo.toml @@ -2,6 +2,7 @@ name = "manual_routes" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/msgpack/Cargo.toml b/examples/msgpack/Cargo.toml index fb5954f6..500b6a6a 100644 --- a/examples/msgpack/Cargo.toml +++ b/examples/msgpack/Cargo.toml @@ -2,6 +2,7 @@ name = "msgpack" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/msgpack/src/main.rs b/examples/msgpack/src/main.rs index 599f1d38..2e514629 100644 --- a/examples/msgpack/src/main.rs +++ b/examples/msgpack/src/main.rs @@ -2,7 +2,6 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate serde_derive; -extern crate rocket_contrib; #[cfg(test)] mod tests; @@ -20,7 +19,7 @@ fn get(id: usize) -> MsgPack> { } #[post("/", data = "", format = "msgpack")] -fn create(data: MsgPack) -> String { +fn create(data: MsgPack>) -> String { data.contents.to_string() } diff --git a/examples/msgpack/src/tests.rs b/examples/msgpack/src/tests.rs index 188e0a20..0c7e3461 100644 --- a/examples/msgpack/src/tests.rs +++ b/examples/msgpack/src/tests.rs @@ -1,4 +1,4 @@ -use rocket; +use crate::rocket; use rocket::local::Client; use rocket::http::{Status, ContentType}; diff --git a/examples/optional_redirect/Cargo.toml b/examples/optional_redirect/Cargo.toml index 501c2118..f802bd7e 100644 --- a/examples/optional_redirect/Cargo.toml +++ b/examples/optional_redirect/Cargo.toml @@ -2,6 +2,7 @@ name = "optional_redirect" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/optional_redirect/src/tests.rs b/examples/optional_redirect/src/tests.rs index 0ce66cbb..2e2875ee 100644 --- a/examples/optional_redirect/src/tests.rs +++ b/examples/optional_redirect/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; use rocket::http::Status; diff --git a/examples/pastebin/Cargo.toml b/examples/pastebin/Cargo.toml index 3809334b..e508d89e 100644 --- a/examples/pastebin/Cargo.toml +++ b/examples/pastebin/Cargo.toml @@ -2,6 +2,7 @@ name = "pastebin" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/pastebin/src/main.rs b/examples/pastebin/src/main.rs index 2aca1fb1..1dddd417 100644 --- a/examples/pastebin/src/main.rs +++ b/examples/pastebin/src/main.rs @@ -1,7 +1,6 @@ #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; -extern crate rand; mod paste_id; #[cfg(test)] mod tests; @@ -13,7 +12,7 @@ use std::path::Path; use rocket::Data; use rocket::response::content; -use paste_id::PasteID; +use crate::paste_id::PasteID; const HOST: &str = "http://localhost:8000"; const ID_LENGTH: usize = 3; @@ -29,7 +28,7 @@ fn upload(paste: Data) -> io::Result { } #[get("/")] -fn retrieve(id: PasteID) -> Option> { +fn retrieve(id: PasteID<'_>) -> Option> { let filename = format!("upload/{id}", id = id); File::open(&filename).map(|f| content::Plain(f)).ok() } diff --git a/examples/pastebin/src/paste_id.rs b/examples/pastebin/src/paste_id.rs index 8fd18c91..736155bd 100644 --- a/examples/pastebin/src/paste_id.rs +++ b/examples/pastebin/src/paste_id.rs @@ -28,7 +28,7 @@ impl<'a> PasteID<'a> { } impl<'a> fmt::Display for PasteID<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } diff --git a/examples/query_params/Cargo.toml b/examples/query_params/Cargo.toml index 71a67273..66795f79 100644 --- a/examples/query_params/Cargo.toml +++ b/examples/query_params/Cargo.toml @@ -2,6 +2,7 @@ name = "query_params" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/query_params/src/tests.rs b/examples/query_params/src/tests.rs index 4390bf72..137a497f 100644 --- a/examples/query_params/src/tests.rs +++ b/examples/query_params/src/tests.rs @@ -11,12 +11,12 @@ macro_rules! run_test { #[test] fn age_and_name_params() { - run_test!("?age=10&name=john", |mut response: Response| { + run_test!("?age=10&name=john", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("Hello, 10 year old named john!".into())); }); - run_test!("?age=20&name=john", |mut response: Response| { + run_test!("?age=20&name=john", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("20 years old? Hi, john!".into())); }); @@ -24,12 +24,12 @@ fn age_and_name_params() { #[test] fn age_param_only() { - run_test!("?age=10", |mut response: Response| { + run_test!("?age=10", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("We're gonna need a name, and only a name.".into())); }); - run_test!("?age=20", |mut response: Response| { + run_test!("?age=20", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("We're gonna need a name, and only a name.".into())); }); @@ -37,19 +37,19 @@ fn age_param_only() { #[test] fn name_param_only() { - run_test!("?name=John", |mut response: Response| { + run_test!("?name=John", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("Hello John!".into())); }); } #[test] fn no_params() { - run_test!("", |mut response: Response| { + run_test!("", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("We're gonna need a name, and only a name.".into())); }); - run_test!("?", |mut response: Response| { + run_test!("?", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("We're gonna need a name, and only a name.".into())); }); @@ -57,12 +57,12 @@ fn no_params() { #[test] fn extra_params() { - run_test!("?age=20&name=Bob&extra", |mut response: Response| { + run_test!("?age=20&name=Bob&extra", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("20 years old? Hi, Bob!".into())); }); - run_test!("?age=30&name=Bob&extra", |mut response: Response| { + run_test!("?age=30&name=Bob&extra", |mut response: Response<'_>| { assert_eq!(response.body_string(), Some("We're gonna need a name, and only a name.".into())); }); @@ -70,7 +70,7 @@ fn extra_params() { #[test] fn wrong_path() { - run_test!("/other?age=20&name=Bob", |response: Response| { + run_test!("/other?age=20&name=Bob", |response: Response<'_>| { assert_eq!(response.status(), Status::NotFound); }); } diff --git a/examples/ranking/Cargo.toml b/examples/ranking/Cargo.toml index 554b6c23..f033e523 100644 --- a/examples/ranking/Cargo.toml +++ b/examples/ranking/Cargo.toml @@ -2,6 +2,7 @@ name = "ranking" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/ranking/src/tests.rs b/examples/ranking/src/tests.rs index b4177cee..e638150a 100644 --- a/examples/ranking/src/tests.rs +++ b/examples/ranking/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; fn test(uri: &str, expected: String) { diff --git a/examples/raw_sqlite/Cargo.toml b/examples/raw_sqlite/Cargo.toml index cda1b782..1b09d9af 100644 --- a/examples/raw_sqlite/Cargo.toml +++ b/examples/raw_sqlite/Cargo.toml @@ -2,6 +2,7 @@ name = "raw_sqlite" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/raw_sqlite/src/main.rs b/examples/raw_sqlite/src/main.rs index cc084652..ac241ee8 100644 --- a/examples/raw_sqlite/src/main.rs +++ b/examples/raw_sqlite/src/main.rs @@ -1,7 +1,7 @@ #![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; -extern crate rusqlite; + use rusqlite::types::ToSql; #[cfg(test)] mod tests; @@ -25,7 +25,7 @@ fn init_database(conn: &Connection) { } #[get("/")] -fn hello(db_conn: State) -> Result { +fn hello(db_conn: State<'_, DbConn>) -> Result { db_conn.lock() .expect("db connection lock") .query_row("SELECT name FROM entries WHERE id = 0", diff --git a/examples/raw_upload/Cargo.toml b/examples/raw_upload/Cargo.toml index 2df5a281..3b3d04d2 100644 --- a/examples/raw_upload/Cargo.toml +++ b/examples/raw_upload/Cargo.toml @@ -2,6 +2,7 @@ name = "raw_upload" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/redirect/Cargo.toml b/examples/redirect/Cargo.toml index 51896793..c7a75678 100644 --- a/examples/redirect/Cargo.toml +++ b/examples/redirect/Cargo.toml @@ -2,6 +2,7 @@ name = "redirect" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/redirect/src/tests.rs b/examples/redirect/src/tests.rs index 7c32d785..51b6deb6 100644 --- a/examples/redirect/src/tests.rs +++ b/examples/redirect/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; use rocket::http::Status; diff --git a/examples/request_guard/Cargo.toml b/examples/request_guard/Cargo.toml index 9d563fd9..ebeeada7 100644 --- a/examples/request_guard/Cargo.toml +++ b/examples/request_guard/Cargo.toml @@ -2,6 +2,7 @@ name = "request_guard" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/request_local_state/Cargo.toml b/examples/request_local_state/Cargo.toml index 523a1103..8322df23 100644 --- a/examples/request_local_state/Cargo.toml +++ b/examples/request_local_state/Cargo.toml @@ -2,6 +2,7 @@ name = "request_local_state" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/request_local_state/src/main.rs b/examples/request_local_state/src/main.rs index 9aa2db17..f4063211 100644 --- a/examples/request_local_state/src/main.rs +++ b/examples/request_local_state/src/main.rs @@ -22,7 +22,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard1 { type Error = (); fn from_request(req: &'a Request<'r>) -> request::Outcome { - let atomics = req.guard::>()?; + let atomics = req.guard::>()?; atomics.uncached.fetch_add(1, Ordering::Relaxed); req.local_cache(|| atomics.cached.fetch_add(1, Ordering::Relaxed)); diff --git a/examples/session/Cargo.toml b/examples/session/Cargo.toml index 4a2de9af..3a367bde 100644 --- a/examples/session/Cargo.toml +++ b/examples/session/Cargo.toml @@ -2,6 +2,7 @@ name = "session" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/session/src/main.rs b/examples/session/src/main.rs index ff6881c0..c4197c6b 100644 --- a/examples/session/src/main.rs +++ b/examples/session/src/main.rs @@ -1,7 +1,6 @@ #![feature(proc_macro_hygiene, decl_macro, never_type)] #[macro_use] extern crate rocket; -extern crate rocket_contrib; #[cfg(test)] mod tests; @@ -35,7 +34,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for User { } #[post("/login", data = "")] -fn login(mut cookies: Cookies, login: Form) -> Result> { +fn login(mut cookies: Cookies<'_>, login: Form) -> Result> { if login.username == "Sergio" && login.password == "password" { cookies.add_private(Cookie::new("user_id", 1.to_string())); Ok(Redirect::to(uri!(index))) @@ -45,7 +44,7 @@ fn login(mut cookies: Cookies, login: Form) -> Result Flash { +fn logout(mut cookies: Cookies<'_>) -> Flash { cookies.remove_private(Cookie::named("user_id")); Flash::success(Redirect::to(uri!(login_page)), "Successfully logged out.") } @@ -56,7 +55,7 @@ fn login_user(_user: User) -> Redirect { } #[get("/login", rank = 2)] -fn login_page(flash: Option) -> Template { +fn login_page(flash: Option>) -> Template { let mut context = HashMap::new(); if let Some(ref msg) = flash { context.insert("flash", msg.msg()); diff --git a/examples/session/src/tests.rs b/examples/session/src/tests.rs index 7530f1a0..d6ab7771 100644 --- a/examples/session/src/tests.rs +++ b/examples/session/src/tests.rs @@ -3,7 +3,7 @@ use rocket::Response; use rocket::local::Client; use rocket::http::{Status, Cookie, ContentType}; -fn user_id_cookie(response: &Response) -> Option> { +fn user_id_cookie(response: &Response<'_>) -> Option> { let cookie = response.headers() .get("Set-Cookie") .filter(|v| v.starts_with("user_id")) diff --git a/examples/state/Cargo.toml b/examples/state/Cargo.toml index c6bd00c5..b102d637 100644 --- a/examples/state/Cargo.toml +++ b/examples/state/Cargo.toml @@ -2,6 +2,7 @@ name = "state" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/state/src/main.rs b/examples/state/src/main.rs index 08556a01..7cc54e6d 100644 --- a/examples/state/src/main.rs +++ b/examples/state/src/main.rs @@ -12,7 +12,7 @@ use rocket::response::content; struct HitCount(AtomicUsize); #[get("/")] -fn index(hit_count: State) -> content::Html { +fn index(hit_count: State<'_, HitCount>) -> content::Html { hit_count.0.fetch_add(1, Ordering::Relaxed); let msg = "Your visit has been recorded!"; let count = format!("Visits: {}", count(hit_count)); @@ -20,7 +20,7 @@ fn index(hit_count: State) -> content::Html { } #[get("/count")] -fn count(hit_count: State) -> String { +fn count(hit_count: State<'_, HitCount>) -> String { hit_count.0.load(Ordering::Relaxed).to_string() } diff --git a/examples/static_files/Cargo.toml b/examples/static_files/Cargo.toml index bb2fa273..a4652463 100644 --- a/examples/static_files/Cargo.toml +++ b/examples/static_files/Cargo.toml @@ -2,6 +2,7 @@ name = "static_files" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/stream/Cargo.toml b/examples/stream/Cargo.toml index 5f6f1b30..96792d90 100644 --- a/examples/stream/Cargo.toml +++ b/examples/stream/Cargo.toml @@ -2,6 +2,7 @@ name = "stream" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/tera_templates/Cargo.toml b/examples/tera_templates/Cargo.toml index 49605b3d..4f656410 100644 --- a/examples/tera_templates/Cargo.toml +++ b/examples/tera_templates/Cargo.toml @@ -2,6 +2,7 @@ name = "tera_templates" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/tera_templates/src/main.rs b/examples/tera_templates/src/main.rs index 8cbbbcc6..2b04cd70 100644 --- a/examples/tera_templates/src/main.rs +++ b/examples/tera_templates/src/main.rs @@ -2,8 +2,6 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate serde_derive; -extern crate serde_json; -extern crate rocket_contrib; #[cfg(test)] mod tests; @@ -31,7 +29,7 @@ fn get(name: String) -> Template { } #[catch(404)] -fn not_found(req: &Request) -> Template { +fn not_found(req: &Request<'_>) -> Template { let mut map = HashMap::new(); map.insert("path", req.uri().path()); Template::render("error/404", &map) diff --git a/examples/tera_templates/src/tests.rs b/examples/tera_templates/src/tests.rs index 425124d3..9fc00270 100644 --- a/examples/tera_templates/src/tests.rs +++ b/examples/tera_templates/src/tests.rs @@ -15,7 +15,7 @@ macro_rules! dispatch { fn test_root() { // Check that the redirect works. for method in &[Get, Head] { - dispatch!(*method, "/", |_: &Client, mut response: LocalResponse| { + dispatch!(*method, "/", |_: &Client, mut response: LocalResponse<'_>| { assert_eq!(response.status(), Status::SeeOther); assert!(response.body().is_none()); @@ -26,8 +26,8 @@ fn test_root() { // Check that other request methods are not accepted (and instead caught). for method in &[Post, Put, Delete, Options, Trace, Connect, Patch] { - dispatch!(*method, "/", |client: &Client, mut response: LocalResponse| { - let mut map = ::std::collections::HashMap::new(); + dispatch!(*method, "/", |client: &Client, mut response: LocalResponse<'_>| { + let mut map = std::collections::HashMap::new(); map.insert("path", "/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); @@ -40,7 +40,7 @@ fn test_root() { #[test] fn test_name() { // Check that the /hello/ route works. - dispatch!(Get, "/hello/Jack", |client: &Client, mut response: LocalResponse| { + dispatch!(Get, "/hello/Jack", |client: &Client, mut response: LocalResponse<'_>| { let context = super::TemplateContext { name: "Jack".into(), items: vec!["One", "Two", "Three"] @@ -55,8 +55,8 @@ fn test_name() { #[test] fn test_404() { // Check that the error catcher works. - dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse| { - let mut map = ::std::collections::HashMap::new(); + dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse<'_>| { + let mut map = std::collections::HashMap::new(); map.insert("path", "/hello/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); diff --git a/examples/testing/Cargo.toml b/examples/testing/Cargo.toml index 8bdcc82b..6ed69497 100644 --- a/examples/testing/Cargo.toml +++ b/examples/testing/Cargo.toml @@ -2,6 +2,7 @@ name = "testing" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/tls/Cargo.toml b/examples/tls/Cargo.toml index 0cc075ed..7f9ff337 100644 --- a/examples/tls/Cargo.toml +++ b/examples/tls/Cargo.toml @@ -2,6 +2,7 @@ name = "tls" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/tls/src/tests.rs b/examples/tls/src/tests.rs index da0b732b..80bf4aeb 100644 --- a/examples/tls/src/tests.rs +++ b/examples/tls/src/tests.rs @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; #[test] diff --git a/examples/todo/Cargo.toml b/examples/todo/Cargo.toml index 797b431a..21662e25 100644 --- a/examples/todo/Cargo.toml +++ b/examples/todo/Cargo.toml @@ -2,6 +2,7 @@ name = "todo" version = "0.0.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/todo/src/main.rs b/examples/todo/src/main.rs index 8ce8c4aa..d3ed0f1f 100644 --- a/examples/todo/src/main.rs +++ b/examples/todo/src/main.rs @@ -17,7 +17,7 @@ use rocket::response::{Flash, Redirect}; use rocket_contrib::{templates::Template, serve::StaticFiles}; use diesel::SqliteConnection; -use task::{Task, Todo}; +use crate::task::{Task, Todo}; // This macro from `diesel_migrations` defines an `embedded_migrations` module // containing a function named `run`. This allows the example to be run and @@ -71,7 +71,7 @@ fn delete(id: i32, conn: DbConn) -> Result, Template> { } #[get("/")] -fn index(msg: Option, conn: DbConn) -> Template { +fn index(msg: Option>, conn: DbConn) -> Template { Template::render("index", &match msg { Some(ref msg) => Context::raw(&conn, Some((msg.name(), msg.msg()))), None => Context::raw(&conn, None), diff --git a/examples/todo/src/tests.rs b/examples/todo/src/tests.rs index a9ca6bae..1553e9ef 100644 --- a/examples/todo/src/tests.rs +++ b/examples/todo/src/tests.rs @@ -1,9 +1,7 @@ -extern crate parking_lot; -extern crate rand; - use super::task::Task; -use self::parking_lot::Mutex; -use self::rand::{Rng, thread_rng, distributions::Alphanumeric}; + +use parking_lot::Mutex; +use rand::{Rng, thread_rng, distributions::Alphanumeric}; use rocket::local::Client; use rocket::http::{Status, ContentType}; diff --git a/examples/uuid/Cargo.toml b/examples/uuid/Cargo.toml index 24018823..476f90d0 100644 --- a/examples/uuid/Cargo.toml +++ b/examples/uuid/Cargo.toml @@ -2,6 +2,7 @@ name = "uuid" version = "0.1.0" workspace = "../../" +edition = "2018" publish = false [dependencies] diff --git a/examples/uuid/src/main.rs b/examples/uuid/src/main.rs index b5463ed5..df9fe13c 100644 --- a/examples/uuid/src/main.rs +++ b/examples/uuid/src/main.rs @@ -2,8 +2,6 @@ #[macro_use] extern crate rocket; #[macro_use] extern crate lazy_static; -extern crate rocket_contrib; -extern crate uuid; use std::collections::HashMap; use rocket_contrib::uuid::Uuid;