Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 9bf585496c3303fc800f4f578da70a9d2179ce63
parent 0612c644ad6ead1d276da3b83a86ab5296941f89
Author: Sean Stangl <sean.stangl@gmail.com>
Date:   Sat, 28 Jul 2018 09:58:10 -0700

Apply more Clippy suggestions.

Diffstat:
Mcontrib/lib/src/json.rs | 10+++++-----
Mcontrib/lib/src/msgpack.rs | 6+++---
Mcontrib/lib/src/templates/context.rs | 2+-
Mcontrib/lib/src/templates/mod.rs | 2+-
Mcontrib/lib/src/uuid.rs | 2+-
Mcore/codegen/src/decorators/route.rs | 10++++------
Mcore/lib/src/catcher.rs | 4++--
Mcore/lib/src/config/config.rs | 6+++---
Mcore/lib/src/config/custom_values.rs | 4++--
Mcore/lib/src/config/environment.rs | 2+-
Mcore/lib/src/config/mod.rs | 5+----
Mcore/lib/src/data/data.rs | 6+-----
Mcore/lib/src/error.rs | 2+-
Mcore/lib/src/request/form/form_items.rs | 5+----
Mcore/lib/src/request/form/lenient.rs | 2+-
Mcore/lib/src/rocket.rs | 2+-
Mexamples/pastebin/src/main.rs | 2+-
Mexamples/pastebin/src/paste_id.rs | 2+-
Mexamples/stream/src/main.rs | 2+-
Mexamples/uuid/src/main.rs | 2+-
20 files changed, 33 insertions(+), 45 deletions(-)

diff --git a/contrib/lib/src/json.rs b/contrib/lib/src/json.rs @@ -113,7 +113,7 @@ impl<T: DeserializeOwned> FromData for Json<T> { let size_limit = request.limits().get("json").unwrap_or(LIMIT); from_reader_eager(data.open().take(size_limit)) - .map(|val| Json(val)) + .map(Json) .map_err(|e| { error_!("Couldn't parse JSON body: {:?}", e); e }) .into_outcome(Status::BadRequest) } @@ -137,14 +137,14 @@ impl<T> Deref for Json<T> { type Target = T; #[inline(always)] - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { &self.0 } } impl<T> DerefMut for Json<T> { #[inline(always)] - fn deref_mut<'a>(&'a mut self) -> &'a mut T { + fn deref_mut(&mut self) -> &mut T { &mut self.0 } } @@ -208,14 +208,14 @@ impl Deref for JsonValue { type Target = serde_json::Value; #[inline(always)] - fn deref<'a>(&'a self) -> &'a Self::Target { + fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for JsonValue { #[inline(always)] - fn deref_mut<'a>(&'a mut self) -> &'a mut Self::Target { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } diff --git a/contrib/lib/src/msgpack.rs b/contrib/lib/src/msgpack.rs @@ -135,7 +135,7 @@ impl<T: DeserializeOwned> FromData for MsgPack<T> { return Outcome::Failure((Status::BadRequest, e)); }; - rmp_serde::from_slice(&buf).map(|val| MsgPack(val)) + rmp_serde::from_slice(&buf).map(MsgPack) .map_err(|e| { error_!("Couldn't parse MessagePack body: {:?}", e); e }) .into_outcome(Status::BadRequest) } @@ -161,14 +161,14 @@ impl<T> Deref for MsgPack<T> { type Target = T; #[inline(always)] - fn deref<'a>(&'a self) -> &'a T { + fn deref(&self) -> &T { &self.0 } } impl<T> DerefMut for MsgPack<T> { #[inline(always)] - fn deref_mut<'a>(&'a mut self) -> &'a mut T { + fn deref_mut(&mut self) -> &mut T { &mut self.0 } } diff --git a/contrib/lib/src/templates/context.rs b/contrib/lib/src/templates/context.rs @@ -43,7 +43,7 @@ impl Context { templates.insert(name, TemplateInfo { path: path.to_path_buf(), extension: ext.to_string(), - data_type: data_type, + data_type, }); } } diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs @@ -29,7 +29,7 @@ use rocket::fairing::Fairing; use rocket::response::{self, Content, Responder}; use rocket::http::{ContentType, Status}; -const DEFAULT_TEMPLATE_DIR: &'static str = "templates"; +const DEFAULT_TEMPLATE_DIR: &str = "templates"; /// The Template type implements generic support for template rendering in /// Rocket. diff --git a/contrib/lib/src/uuid.rs b/contrib/lib/src/uuid.rs @@ -110,7 +110,7 @@ impl FromStr for Uuid { impl Deref for Uuid { type Target = uuid_ext::Uuid; - fn deref<'a>(&'a self) -> &'a Self::Target { + fn deref(&self) -> &Self::Target { &self.0 } } diff --git a/core/codegen/src/decorators/route.rs b/core/codegen/src/decorators/route.rs @@ -87,12 +87,10 @@ impl RouteParams { } fn generate_data_statement(&self, ecx: &ExtCtxt) -> Option<Stmt> { - let param = self.data_param.as_ref().map(|p| &p.value); - let arg = param.and_then(|p| self.annotated_fn.find_input(&p.node.name)); - if param.is_none() { - return None; - } else if arg.is_none() { - self.missing_declared_err(ecx, param.unwrap()); + let param = self.data_param.as_ref().map(|p| &p.value)?; + let arg = self.annotated_fn.find_input(&param.node.name); + if arg.is_none() { + self.missing_declared_err(ecx, param); return None; } diff --git a/core/lib/src/catcher.rs b/core/lib/src/catcher.rs @@ -95,7 +95,7 @@ impl Catcher { /// ``` #[inline(always)] pub fn new(code: u16, handler: ErrorHandler) -> Catcher { - Catcher { code: code, handler: handler, is_default: false } + Catcher { code, handler, is_default: false } } #[inline(always)] @@ -105,7 +105,7 @@ impl Catcher { #[inline(always)] fn new_default(code: u16, handler: ErrorHandler) -> Catcher { - Catcher { code: code, handler: handler, is_default: true, } + Catcher { code, handler, is_default: true, } } #[inline(always)] diff --git a/core/lib/src/config/config.rs b/core/lib/src/config/config.rs @@ -249,7 +249,7 @@ impl Config { tls: None, limits: Limits::default(), extras: HashMap::new(), - config_path: config_path, + config_path, } } Staging => { @@ -264,7 +264,7 @@ impl Config { tls: None, limits: Limits::default(), extras: HashMap::new(), - config_path: config_path, + config_path, } } Production => { @@ -279,7 +279,7 @@ impl Config { tls: None, limits: Limits::default(), extras: HashMap::new(), - config_path: config_path, + config_path, } } }) diff --git a/core/lib/src/config/custom_values.rs b/core/lib/src/config/custom_values.rs @@ -129,7 +129,7 @@ impl Limits { "forms" => self.forms = limit, _ => { let mut found = false; - for tuple in self.extra.iter_mut() { + for tuple in &mut self.extra { if tuple.0 == name { tuple.1 = limit; found = true; @@ -199,7 +199,7 @@ impl fmt::Display for Limits { } pub fn str<'a>(conf: &Config, name: &str, v: &'a Value) -> Result<&'a str> { - v.as_str().ok_or(conf.bad_type(name, v.type_str(), "a string")) + v.as_str().ok_or_else(|| conf.bad_type(name, v.type_str(), "a string")) } pub fn u64(conf: &Config, name: &str, value: &Value) -> Result<u64> { diff --git a/core/lib/src/config/environment.rs b/core/lib/src/config/environment.rs @@ -6,7 +6,7 @@ use std::env; use self::Environment::*; -pub const CONFIG_ENV: &'static str = "ROCKET_ENV"; +pub const CONFIG_ENV: &str = "ROCKET_ENV"; /// An enum corresponding to the valid configuration environments. #[derive(Hash, PartialEq, Eq, Debug, Clone, Copy)] diff --git a/core/lib/src/config/mod.rs b/core/lib/src/config/mod.rs @@ -262,10 +262,7 @@ impl RocketConfig { configs.insert(Production, Config::default(Production, &f).unwrap()); configs.insert(active_env, config); - RocketConfig { - active_env: active_env, - config: configs - } + RocketConfig { active_env, config: configs } } /// Read the configuration from the `Rocket.toml` file. The file is search diff --git a/core/lib/src/data/data.rs b/core/lib/src/data/data.rs @@ -260,11 +260,7 @@ impl Data { }; trace_!("Peek bytes: {}/{} bytes.", peek_buf.len(), PEEK_BYTES); - Data { - buffer: peek_buf, - stream: stream, - is_complete: eof, - } + Data { buffer: peek_buf, stream, is_complete: eof } } /// This creates a `data` object from a local data source `data`. diff --git a/core/lib/src/error.rs b/core/lib/src/error.rs @@ -99,7 +99,7 @@ pub struct LaunchError { impl LaunchError { #[inline(always)] crate fn new(kind: LaunchErrorKind) -> LaunchError { - LaunchError { handled: AtomicBool::new(false), kind: kind } + LaunchError { handled: AtomicBool::new(false), kind } } #[inline(always)] diff --git a/core/lib/src/request/form/form_items.rs b/core/lib/src/request/form/form_items.rs @@ -197,10 +197,7 @@ impl<'f> From<&'f RawStr> for FormItems<'f> { /// `x-www-form-urlencoded` form `string`. #[inline(always)] fn from(string: &'f RawStr) -> FormItems<'f> { - FormItems { - string: string, - next_index: 0 - } + FormItems { string, next_index: 0 } } } diff --git a/core/lib/src/request/form/lenient.rs b/core/lib/src/request/form/lenient.rs @@ -161,6 +161,6 @@ impl<'f, T: FromForm<'f>> FromData for LenientForm<'f, T> where T::Error: Debug /// logging format. #[inline] fn from_data(request: &Request, data: Data) -> data::Outcome<Self, Self::Error> { - super::from_data(request, data, false).map(|form| LenientForm(form)) + super::from_data(request, data, false).map(LenientForm) } } diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs @@ -427,7 +427,7 @@ impl Rocket { } Rocket { - config: config, + config, router: Router::new(), default_catchers: catcher::defaults::get(), catchers: catcher::defaults::get(), diff --git a/examples/pastebin/src/main.rs b/examples/pastebin/src/main.rs @@ -16,7 +16,7 @@ use rocket::response::content; use paste_id::PasteID; -const HOST: &'static str = "http://localhost:8000"; +const HOST: &str = "http://localhost:8000"; const ID_LENGTH: usize = 3; #[post("/", data = "<paste>")] diff --git a/examples/pastebin/src/paste_id.rs b/examples/pastebin/src/paste_id.rs @@ -6,7 +6,7 @@ use rocket::http::RawStr; use rand::{self, Rng}; /// Table to retrieve base62 values from. -const BASE62: &'static [u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +const BASE62: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; /// A _probably_ unique paste ID. pub struct PasteID<'a>(Cow<'a, str>); diff --git a/examples/stream/src/main.rs b/examples/stream/src/main.rs @@ -13,7 +13,7 @@ use std::fs::File; type LimitedRepeat = Take<Repeat>; // Generate this file using: head -c BYTES /dev/random > big_file.dat -const FILENAME: &'static str = "big_file.dat"; +const FILENAME: &str = "big_file.dat"; #[get("/")] fn root() -> content::Plain<Stream<LimitedRepeat>> { diff --git a/examples/uuid/src/main.rs b/examples/uuid/src/main.rs @@ -35,7 +35,7 @@ fn people(id: Uuid) -> Result<String, String> { // rocket_contrib::Uuid to uuid::Uuid. Ok(PEOPLE.get(&id) .map(|person| format!("We found: {}", person)) - .ok_or(format!("Person not found for UUID: {}", id))?) + .ok_or_else(|| format!("Person not found for UUID: {}", id))?) } fn rocket() -> rocket::Rocket {