Skip to content

Commit

Permalink
Migrate core to Rust 2018.
Browse files Browse the repository at this point in the history
  • Loading branch information
jebrosen authored and SergioBenitez committed Jun 25, 2019
1 parent 90e37be commit 34cb1c1
Show file tree
Hide file tree
Showing 57 changed files with 467 additions and 480 deletions.
1 change: 1 addition & 0 deletions core/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keywords = ["rocket", "web", "framework", "server"]
license = "MIT/Apache-2.0"
build = "build.rs"
categories = ["web-programming::http-server"]
edition = "2018"

[package.metadata.docs.rs]
all-features = true
Expand Down
3 changes: 0 additions & 3 deletions core/lib/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
//! Ensures Rocket isn't compiled with an incompatible version of Rust.

extern crate yansi;
extern crate version_check;

use yansi::{Paint, Color::{Red, Yellow, Blue}};

// Specifies the minimum nightly version needed to compile Rocket.
Expand Down
22 changes: 11 additions & 11 deletions core/lib/src/catcher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use response;
use handler::ErrorHandler;
use codegen::StaticCatchInfo;
use request::Request;
use crate::response;
use crate::handler::ErrorHandler;
use crate::codegen::StaticCatchInfo;
use crate::request::Request;

use std::fmt;
use yansi::Color::*;
Expand All @@ -10,7 +10,7 @@ use yansi::Color::*;
///
/// Catchers are routes that run when errors occur. They correspond directly
/// with the HTTP error status code they will be handling and are registered
/// with Rocket via [`Rocket::register()`](::Rocket::register()). For example,
/// with Rocket via [`Rocket::register()`](crate::Rocket::register()). For example,
/// to handle "404 not found" errors, a catcher for the "404" status code is
/// registered.
///
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Catcher {
}

#[inline(always)]
crate fn handle<'r>(&self, req: &'r Request) -> response::Result<'r> {
crate fn handle<'r>(&self, req: &'r Request<'_>) -> response::Result<'r> {
(self.handler)(req)
}

Expand All @@ -116,7 +116,7 @@ impl<'a> From<&'a StaticCatchInfo> for Catcher {
}

impl fmt::Display for Catcher {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", Blue.paint(&self.code))
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ macro_rules! default_catchers {
let mut map = HashMap::new();

$(
fn $fn_name<'r>(req: &'r Request) -> response::Result<'r> {
fn $fn_name<'r>(req: &'r Request<'_>) -> response::Result<'r> {
status::Custom(Status::from_code($code).unwrap(),
content::Html(error_page_template!($code, $name, $description))
).respond_to(req)
Expand All @@ -167,9 +167,9 @@ pub mod defaults {

use std::collections::HashMap;

use request::Request;
use response::{self, content, status, Responder};
use http::Status;
use crate::request::Request;
use crate::response::{self, content, status, Responder};
use crate::http::Status;

pub fn get() -> HashMap<u16, Catcher> {
default_catchers! {
Expand Down
8 changes: 4 additions & 4 deletions core/lib/src/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {Request, Data};
use handler::{Outcome, ErrorHandler};
use http::{Method, MediaType};
use crate::{Request, Data};
use crate::handler::{Outcome, ErrorHandler};
use crate::http::{Method, MediaType};

/// Type of a static handler, which users annotate with Rocket's attribute.
pub type StaticHandler = for<'r> fn(&'r Request, Data) -> Outcome<'r>;
pub type StaticHandler = for<'r> fn(&'r Request<'_>, Data) -> Outcome<'r>;

/// Information generated by the `route` attribute during codegen.
pub struct StaticRouteInfo {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/config/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use config::{Result, Config, Value, Environment, Limits, LoggingLevel};
use crate::config::{Result, Config, Value, Environment, Limits, LoggingLevel};

/// Structure following the builder pattern for building `Config` structures.
#[derive(Clone)]
Expand Down
26 changes: 13 additions & 13 deletions core/lib/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::path::{Path, PathBuf};
use std::convert::AsRef;
use std::fmt;

use crate::config::Environment::*;
use crate::config::{Result, ConfigBuilder, Environment, ConfigError, LoggingLevel};
use crate::config::{Table, Value, Array, Datetime};
use crate::http::private::Key;

use super::custom_values::*;
use {num_cpus, base64};
use config::Environment::*;
use config::{Result, ConfigBuilder, Environment, ConfigError, LoggingLevel};
use config::{Table, Value, Array, Datetime};

use http::private::Key;

/// Structure for Rocket application configuration.
///
Expand All @@ -33,7 +33,7 @@ use http::private::Key;
/// ## General Configuration
///
/// For more information about Rocket's configuration, see the
/// [`config`](::config) module documentation.
/// [`config`](crate::config) module documentation.
#[derive(Clone)]
pub struct Config {
/// The environment that this configuration corresponds to.
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Config {
}

/// Returns a `Config` with the default parameters for the environment
/// `env`. See [`config`](::config) for a list of defaults.
/// `env`. See [`config`](crate::config) for a list of defaults.
///
/// # Example
///
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Config {
}

/// Returns a `Config` with the default parameters of the development
/// environment. See [`config`](::config) for a list of defaults.
/// environment. See [`config`](crate::config) for a list of defaults.
///
/// # Example
///
Expand All @@ -153,7 +153,7 @@ impl Config {
}

/// Returns a `Config` with the default parameters of the staging
/// environment. See [`config`](::config) for a list of defaults.
/// environment. See [`config`](crate::config) for a list of defaults.
///
/// # Example
///
Expand All @@ -168,7 +168,7 @@ impl Config {
}

/// Returns a `Config` with the default parameters of the production
/// environment. See [`config`](::config) for a list of defaults.
/// environment. See [`config`](crate::config) for a list of defaults.
///
/// # Example
///
Expand Down Expand Up @@ -518,7 +518,7 @@ impl Config {
/// ```
#[cfg(feature = "tls")]
pub fn set_tls(&mut self, certs_path: &str, key_path: &str) -> Result<()> {
use http::tls::util::{self, Error};
use crate::http::tls::util::{self, Error};

let pem_err = "malformed PEM file";

Expand Down Expand Up @@ -908,7 +908,7 @@ impl Config {
path.into()
} else if let Some(root) = self.root() {
root.join(path)
} else if let Ok(cwd) = ::std::env::current_dir() {
} else if let Ok(cwd) = std::env::current_dir() {
cwd.join(path)
} else {
path.into()
Expand All @@ -917,7 +917,7 @@ impl Config {
}

impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("Config");
s.field("environment", &self.environment);
s.field("address", &self.address);
Expand Down
15 changes: 7 additions & 8 deletions core/lib/src/config/custom_values.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::fmt;

#[cfg(feature = "tls")]
use http::tls::{Certificate, PrivateKey};
use http::private::Key;
#[cfg(feature = "tls")] use crate::http::tls::{Certificate, PrivateKey};

use config::{Result, Config, Value, ConfigError, LoggingLevel};
use crate::http::private::Key;
use crate::config::{Result, Config, Value, ConfigError, LoggingLevel};

#[derive(Clone)]
pub enum SecretKey {
Expand All @@ -31,7 +30,7 @@ impl SecretKey {
}

impl fmt::Display for SecretKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[cfg(feature = "private-cookies")]
match *self {
SecretKey::Generated(_) => write!(f, "generated"),
Expand Down Expand Up @@ -64,7 +63,7 @@ pub struct TlsConfig;
///
/// # Defaults
///
/// As documented in [`config`](::config), the default limits are as follows:
/// As documented in [`config`](crate::config), the default limits are as follows:
///
/// * **forms**: 32KiB
///
Expand Down Expand Up @@ -180,8 +179,8 @@ impl Limits {
}

impl fmt::Display for Limits {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt_size(n: u64, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_size(n: u64, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if (n & ((1 << 20) - 1)) == 0 {
write!(f, "{}MiB", n >> 20)
} else if (n & ((1 << 10) - 1)) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/config/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl FromStr for Environment {
}

impl fmt::Display for Environment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Development => write!(f, "development"),
Staging => write!(f, "staging"),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/config/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl ConfigError {
}

impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
NotFound => write!(f, "config file was not found"),
IoError => write!(f, "I/O error while reading the config file"),
Expand Down
16 changes: 8 additions & 8 deletions core/lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
//! [`Config`] structure.
//!
//! The retrivial of configuration parameters usually occurs at launch time via
//! a [launch fairing](::fairing::Fairing). If information about the
//! a [launch fairing](crate::fairing::Fairing). If information about the
//! configuraiton is needed later in the program, an attach fairing can be used
//! to store the information as managed state. As an example of the latter,
//! consider the following short program which reads the `token` configuration
Expand Down Expand Up @@ -203,23 +203,23 @@ pub use self::error::ConfigError;
pub use self::environment::Environment;
pub use self::config::Config;
pub use self::builder::ConfigBuilder;
pub use logger::LoggingLevel;
pub use crate::logger::LoggingLevel;
crate use self::toml_ext::LoggedValue;

use logger;
use crate::logger;
use self::Environment::*;
use self::environment::CONFIG_ENV;
use logger::COLORS_ENV;
use crate::logger::COLORS_ENV;
use self::toml_ext::parse_simple_toml_value;
use http::uncased::uncased_eq;
use crate::http::uncased::uncased_eq;

const CONFIG_FILENAME: &str = "Rocket.toml";
const GLOBAL_ENV_NAME: &str = "global";
const ENV_VAR_PREFIX: &str = "ROCKET_";
const PREHANDLED_VARS: [&str; 3] = ["ROCKET_CODEGEN_DEBUG", CONFIG_ENV, COLORS_ENV];

/// Wraps `std::result` with the error type of [`ConfigError`].
pub type Result<T> = ::std::result::Result<T, ConfigError>;
pub type Result<T> = std::result::Result<T, ConfigError>;

#[doc(hidden)]
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -478,12 +478,12 @@ mod test {
use super::Environment::*;
use super::Result;

use ::logger::LoggingLevel;
use crate::logger::LoggingLevel;

const TEST_CONFIG_FILENAME: &'static str = "/tmp/testing/Rocket.toml";

// TODO: It's a shame we have to depend on lazy_static just for this.
lazy_static! {
lazy_static::lazy_static! {
static ref ENV_LOCK: Mutex<usize> = Mutex::new(0);
}

Expand Down
10 changes: 5 additions & 5 deletions core/lib/src/config/toml_ext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use std::result::Result as StdResult;

use config::Value;
use crate::config::Value;

use pear::{Result, parser, switch};
use pear::parsers::*;
Expand All @@ -24,7 +24,7 @@ fn is_not_separator(byte: char) -> bool {
#[inline(always)]
fn is_ident_char(byte: char) -> bool {
match byte {
'0'...'9' | 'A'...'Z' | 'a'...'z' | '_' | '-' => true,
'0'..='9' | 'A'..='Z' | 'a'..='z' | '_' | '-' => true,
_ => false
}
}
Expand Down Expand Up @@ -83,10 +83,10 @@ pub fn parse_simple_toml_value(mut input: &str) -> StdResult<Value, String> {
/// `Display`. This is used to log config values at initialization.
crate struct LoggedValue<'a>(pub &'a Value);

impl<'a> fmt::Display for LoggedValue<'a> {
impl fmt::Display for LoggedValue<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use config::Value::*;
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use crate::config::Value::*;
match *self.0 {
String(_) | Integer(_) | Float(_) | Boolean(_) | Datetime(_) | Array(_) => {
self.0.fmt(f)
Expand Down
Loading

0 comments on commit 34cb1c1

Please sign in to comment.