Rocket

A web framework for Rust. https://rocket.rs (mirror)
git clone git://git.thc420.xyz/Rocket
Log | Files | Refs | README

commit d9f989a49616658878dfb3e9f37d52608e134e2a
parent 23151719719b44985284b4334b00bc74fb2d7f1c
Author: Jeb Rosen <jeb@jebrosen.com>
Date:   Wed, 12 Jun 2019 19:41:29 -0700

Migrate all examples to Rust 2018.

Diffstat:
Mexamples/config/Cargo.toml | 1+
Mexamples/config/src/main.rs | 2--
Mexamples/config/tests/common/mod.rs | 6+++---
Mexamples/content_types/Cargo.toml | 1+
Mexamples/content_types/src/main.rs | 3+--
Mexamples/content_types/src/tests.rs | 2--
Mexamples/cookies/Cargo.toml | 1+
Mexamples/cookies/src/main.rs | 5++---
Mexamples/errors/Cargo.toml | 1+
Mexamples/errors/src/main.rs | 2+-
Mexamples/errors/src/tests.rs | 1-
Mexamples/fairings/Cargo.toml | 1+
Mexamples/fairings/src/main.rs | 6+++---
Mexamples/form_kitchen_sink/Cargo.toml | 1+
Mexamples/form_kitchen_sink/src/main.rs | 2+-
Mexamples/form_kitchen_sink/src/tests.rs | 8++++----
Mexamples/form_validation/Cargo.toml | 1+
Mexamples/form_validation/src/main.rs | 2+-
Mexamples/handlebars_templates/Cargo.toml | 1+
Mexamples/handlebars_templates/src/main.rs | 13++++++-------
Mexamples/handlebars_templates/src/tests.rs | 12++++++------
Mexamples/hello_2018/Cargo.toml | 2+-
Mexamples/hello_person/Cargo.toml | 1+
Mexamples/hello_person/src/tests.rs | 1-
Mexamples/hello_world/Cargo.toml | 1+
Mexamples/hello_world/src/tests.rs | 1-
Mexamples/json/Cargo.toml | 1+
Mexamples/json/src/main.rs | 6+++---
Mexamples/json/src/tests.rs | 2+-
Mexamples/managed_queue/Cargo.toml | 1+
Mexamples/managed_queue/src/main.rs | 5++---
Mexamples/manual_routes/Cargo.toml | 1+
Mexamples/msgpack/Cargo.toml | 1+
Mexamples/msgpack/src/main.rs | 3+--
Mexamples/msgpack/src/tests.rs | 2+-
Mexamples/optional_redirect/Cargo.toml | 1+
Mexamples/optional_redirect/src/tests.rs | 1-
Mexamples/pastebin/Cargo.toml | 1+
Mexamples/pastebin/src/main.rs | 5++---
Mexamples/pastebin/src/paste_id.rs | 2+-
Mexamples/query_params/Cargo.toml | 1+
Mexamples/query_params/src/tests.rs | 20++++++++++----------
Mexamples/ranking/Cargo.toml | 1+
Mexamples/ranking/src/tests.rs | 1-
Mexamples/raw_sqlite/Cargo.toml | 1+
Mexamples/raw_sqlite/src/main.rs | 4++--
Mexamples/raw_upload/Cargo.toml | 1+
Mexamples/redirect/Cargo.toml | 1+
Mexamples/redirect/src/tests.rs | 1-
Mexamples/request_guard/Cargo.toml | 1+
Mexamples/request_local_state/Cargo.toml | 1+
Mexamples/request_local_state/src/main.rs | 2+-
Mexamples/session/Cargo.toml | 1+
Mexamples/session/src/main.rs | 7+++----
Mexamples/session/src/tests.rs | 2+-
Mexamples/state/Cargo.toml | 1+
Mexamples/state/src/main.rs | 4++--
Mexamples/static_files/Cargo.toml | 1+
Mexamples/stream/Cargo.toml | 1+
Mexamples/tera_templates/Cargo.toml | 1+
Mexamples/tera_templates/src/main.rs | 4+---
Mexamples/tera_templates/src/tests.rs | 12++++++------
Mexamples/testing/Cargo.toml | 1+
Mexamples/tls/Cargo.toml | 1+
Mexamples/tls/src/tests.rs | 1-
Mexamples/todo/Cargo.toml | 1+
Mexamples/todo/src/main.rs | 4++--
Mexamples/todo/src/tests.rs | 8+++-----
Mexamples/uuid/Cargo.toml | 1+
Mexamples/uuid/src/main.rs | 2--
70 files changed, 103 insertions(+), 95 deletions(-)

diff --git 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 @@ -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 @@ -7,8 +7,8 @@ use rocket::local::Client; struct LocalConfig(Config); #[get("/check_config")] -fn check_config(config: State<LocalConfig>) -> 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<LocalConfig>) -> 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 @@ -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 @@ -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<content::Json<String>> { } #[catch(404)] -fn not_found(request: &Request) -> content::Html<String> { +fn not_found(request: &Request<'_>) -> content::Html<String> { let html = match request.format() { Some(ref mt) if !mt.is_json() && !mt.is_plain() => { format!("<p>'{}' requests are not supported.</p>", mt) diff --git 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 @@ -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 @@ -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 = "<message>")] -fn submit(mut cookies: Cookies, message: Form<Message>) -> Redirect { +fn submit(mut cookies: Cookies<'_>, message: Form<Message>) -> 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 @@ -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 @@ -12,7 +12,7 @@ fn hello(name: String, age: i8) -> String { } #[catch(404)] -fn not_found(req: &rocket::Request) -> content::Html<String> { +fn not_found(req: &rocket::Request<'_>) -> content::Html<String> { content::Html(format!("<p>Sorry, but '{}' is not a valid path!</p> <p>Try visiting /hello/&lt;name&gt;/&lt;age&gt; instead.</p>", req.uri())) diff --git 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 @@ -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 @@ -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<Token>) -> 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 @@ -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 @@ -28,7 +28,7 @@ struct FormInput<'r> { } #[post("/", data = "<sink>")] -fn sink(sink: Result<Form<FormInput>, FormError>) -> String { +fn sink(sink: Result<Form<FormInput<'_>>, 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 @@ -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 @@ -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 @@ -51,7 +51,7 @@ impl<'v> FromFormValue<'v> for AdultAge { } #[post("/login", data = "<user>")] -fn login(user: Form<UserLogin>) -> Result<Redirect, String> { +fn login(user: Form<UserLogin<'_>>) -> Result<Redirect, String> { 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 @@ -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 @@ -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("<b><i>")?; diff --git 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/<name> 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; #[test] diff --git 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 @@ -26,7 +26,7 @@ struct Message { // TODO: This example can be improved by using `route` with multiple HTTP verbs. #[post("/<id>", format = "json", data = "<message>")] -fn new(id: ID, message: Json<Message>, map: State<MessageMap>) -> JsonValue { +fn new(id: ID, message: Json<Message>, 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<Message>, map: State<MessageMap>) -> JsonValue { } #[put("/<id>", format = "json", data = "<message>")] -fn update(id: ID, message: Json<Message>, map: State<MessageMap>) -> Option<JsonValue> { +fn update(id: ID, message: Json<Message>, map: State<'_, MessageMap>) -> Option<JsonValue> { 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<Message>, map: State<MessageMap>) -> Option<Json } #[get("/<id>", format = "json")] -fn get(id: ID, map: State<MessageMap>) -> Option<Json<Message>> { +fn get(id: ID, map: State<'_, MessageMap>) -> Option<Json<Message>> { 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 @@ -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 @@ -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 @@ -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<String>); #[put("/push?<event>")] -fn push(event: String, queue: State<LogChannel>) { +fn push(event: String, queue: State<'_, LogChannel>) { queue.0.push(event); } #[get("/pop")] -fn pop(queue: State<LogChannel>) -> Option<String> { +fn pop(queue: State<'_, LogChannel>) -> Option<String> { queue.0.pop().ok() } diff --git 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 @@ -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 @@ -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<Message<'static>> { } #[post("/", data = "<data>", format = "msgpack")] -fn create(data: MsgPack<Message>) -> String { +fn create(data: MsgPack<Message<'_>>) -> String { data.contents.to_string() } diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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<String> { } #[get("/<id>")] -fn retrieve(id: PasteID) -> Option<content::Plain<File>> { +fn retrieve(id: PasteID<'_>) -> Option<content::Plain<File>> { 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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<DbConn>) -> Result<String, Error> { +fn hello(db_conn: State<'_, DbConn>) -> Result<String, Error> { 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -22,7 +22,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard1 { type Error = (); fn from_request(req: &'a Request<'r>) -> request::Outcome<Self, ()> { - let atomics = req.guard::<State<Atomics>>()?; + let atomics = req.guard::<State<'_, Atomics>>()?; 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 @@ -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 @@ -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 = "<login>")] -fn login(mut cookies: Cookies, login: Form<Login>) -> Result<Redirect, Flash<Redirect>> { +fn login(mut cookies: Cookies<'_>, login: Form<Login>) -> Result<Redirect, Flash<Redirect>> { 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<Login>) -> Result<Redirect, Flash<Red } #[post("/logout")] -fn logout(mut cookies: Cookies) -> Flash<Redirect> { +fn logout(mut cookies: Cookies<'_>) -> Flash<Redirect> { 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<FlashMessage>) -> Template { +fn login_page(flash: Option<FlashMessage<'_, '_>>) -> 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 @@ -3,7 +3,7 @@ use rocket::Response; use rocket::local::Client; use rocket::http::{Status, Cookie, ContentType}; -fn user_id_cookie(response: &Response) -> Option<Cookie<'static>> { +fn user_id_cookie(response: &Response<'_>) -> Option<Cookie<'static>> { 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 @@ -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 @@ -12,7 +12,7 @@ use rocket::response::content; struct HitCount(AtomicUsize); #[get("/")] -fn index(hit_count: State<HitCount>) -> content::Html<String> { +fn index(hit_count: State<'_, HitCount>) -> content::Html<String> { 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<HitCount>) -> content::Html<String> { } #[get("/count")] -fn count(hit_count: State<HitCount>) -> 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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/<name> 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 @@ -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 @@ -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 @@ -1,4 +1,3 @@ -use super::rocket; use rocket::local::Client; #[test] diff --git 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 @@ -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<Flash<Redirect>, Template> { } #[get("/")] -fn index(msg: Option<FlashMessage>, conn: DbConn) -> Template { +fn index(msg: Option<FlashMessage<'_, '_>>, 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 @@ -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 @@ -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 @@ -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;