cargo fix --edition

This commit is contained in:
Yong Wen Chua 2018-10-31 10:30:58 +08:00
parent 4dda14373a
commit 086f018bb9
No known key found for this signature in database
GPG Key ID: EDC57EEC439CF10B
4 changed files with 25 additions and 22 deletions

View File

@ -6,7 +6,7 @@ extern crate rocket;
extern crate rocket_cors as cors; extern crate rocket_cors as cors;
extern crate serde_json; extern crate serde_json;
use cors::{AllowedHeaders, AllowedOrigins, Cors}; use crate::cors::{AllowedHeaders, AllowedOrigins, Cors};
use rocket::http::Method; use rocket::http::Method;
fn main() { fn main() {

View File

@ -4,7 +4,9 @@ use std::str::FromStr;
use rocket::http::{self, uri::Origin, Header, Status}; use rocket::http::{self, uri::Origin, Header, Status};
use rocket::{self, Outcome, Request}; use rocket::{self, Outcome, Request};
use {actual_request_response, origin, preflight_response, request_headers, validate, Cors, Error}; use crate::{
actual_request_response, origin, preflight_response, request_headers, validate, Cors, Error,
};
/// An injected header to quickly give the result of CORS /// An injected header to quickly give the result of CORS
static CORS_HEADER: &str = "ROCKET-CORS"; static CORS_HEADER: &str = "ROCKET-CORS";
@ -176,7 +178,7 @@ mod tests {
use rocket::local::Client; use rocket::local::Client;
use rocket::Rocket; use rocket::Rocket;
use {AllOrSome, AllowedHeaders, AllowedOrigins, Cors}; use crate::{AllOrSome, AllowedHeaders, AllowedOrigins, Cors};
const CORS_ROOT: &'static str = "/my_cors"; const CORS_ROOT: &'static str = "/my_cors";

View File

@ -89,13 +89,13 @@ impl FromStr for Url {
} }
impl<'a, 'r> FromRequest<'a, 'r> for Url { impl<'a, 'r> FromRequest<'a, 'r> for Url {
type Error = ::Error; type Error = crate::Error;
fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, ::Error> { fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, crate::Error> {
match request.headers().get_one("Origin") { match request.headers().get_one("Origin") {
Some(origin) => match Self::from_str(origin) { Some(origin) => match Self::from_str(origin) {
Ok(origin) => Outcome::Success(origin), Ok(origin) => Outcome::Success(origin),
Err(e) => Outcome::Failure((Status::BadRequest, ::Error::BadOrigin(e))), Err(e) => Outcome::Failure((Status::BadRequest, crate::Error::BadOrigin(e))),
}, },
None => Outcome::Forward(()), None => Outcome::Forward(()),
} }
@ -113,24 +113,24 @@ pub type Origin = Url;
/// You can use this as a rocket [Request Guard](https://rocket.rs/guide/requests/#request-guards) /// You can use this as a rocket [Request Guard](https://rocket.rs/guide/requests/#request-guards)
/// to ensure that the header is passed in correctly. /// to ensure that the header is passed in correctly.
#[derive(Debug)] #[derive(Debug)]
pub struct AccessControlRequestMethod(pub ::Method); pub struct AccessControlRequestMethod(pub crate::Method);
impl FromStr for AccessControlRequestMethod { impl FromStr for AccessControlRequestMethod {
type Err = (); type Err = ();
fn from_str(method: &str) -> Result<Self, Self::Err> { fn from_str(method: &str) -> Result<Self, Self::Err> {
Ok(AccessControlRequestMethod(::Method::from_str(method)?)) Ok(AccessControlRequestMethod(crate::Method::from_str(method)?))
} }
} }
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod { impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod {
type Error = ::Error; type Error = crate::Error;
fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, ::Error> { fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, crate::Error> {
match request.headers().get_one("Access-Control-Request-Method") { match request.headers().get_one("Access-Control-Request-Method") {
Some(request_method) => match Self::from_str(request_method) { Some(request_method) => match Self::from_str(request_method) {
Ok(request_method) => Outcome::Success(request_method), Ok(request_method) => Outcome::Success(request_method),
Err(_) => Outcome::Failure((Status::BadRequest, ::Error::BadRequestMethod)), Err(_) => Outcome::Failure((Status::BadRequest, crate::Error::BadRequestMethod)),
}, },
None => Outcome::Forward(()), None => Outcome::Forward(()),
} }
@ -163,9 +163,9 @@ impl FromStr for AccessControlRequestHeaders {
} }
impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestHeaders { impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestHeaders {
type Error = ::Error; type Error = crate::Error;
fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, ::Error> { fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome<Self, crate::Error> {
match request.headers().get_one("Access-Control-Request-Headers") { match request.headers().get_one("Access-Control-Request-Headers") {
Some(request_headers) => match Self::from_str(request_headers) { Some(request_headers) => match Self::from_str(request_headers) {
Ok(request_headers) => Outcome::Success(request_headers), Ok(request_headers) => Outcome::Success(request_headers),
@ -220,7 +220,8 @@ mod tests {
let origin = hyper::header::Origin::new("https", "www.example.com", None); let origin = hyper::header::Origin::new("https", "www.example.com", None);
request.add_header(origin); request.add_header(origin);
let outcome: request::Outcome<Origin, ::Error> = FromRequest::from_request(request.inner()); let outcome: request::Outcome<Origin, crate::Error> =
FromRequest::from_request(request.inner());
let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s);
assert_eq!("https://www.example.com/", parsed_header.as_str()); assert_eq!("https://www.example.com/", parsed_header.as_str());
} }
@ -231,14 +232,14 @@ mod tests {
let parsed_method = not_err!(AccessControlRequestMethod::from_str(method)); let parsed_method = not_err!(AccessControlRequestMethod::from_str(method));
assert_matches!( assert_matches!(
parsed_method, parsed_method,
AccessControlRequestMethod(::Method(rocket::http::Method::Post)) AccessControlRequestMethod(crate::Method(rocket::http::Method::Post))
); );
let method = "options"; let method = "options";
let parsed_method = not_err!(AccessControlRequestMethod::from_str(method)); let parsed_method = not_err!(AccessControlRequestMethod::from_str(method));
assert_matches!( assert_matches!(
parsed_method, parsed_method,
AccessControlRequestMethod(::Method(rocket::http::Method::Options)) AccessControlRequestMethod(crate::Method(rocket::http::Method::Options))
); );
let method = "INVALID"; let method = "INVALID";
@ -251,7 +252,7 @@ mod tests {
let mut request = client.get("/"); let mut request = client.get("/");
let method = hyper::header::AccessControlRequestMethod(hyper::method::Method::Get); let method = hyper::header::AccessControlRequestMethod(hyper::method::Method::Get);
request.add_header(method); request.add_header(method);
let outcome: request::Outcome<AccessControlRequestMethod, ::Error> = let outcome: request::Outcome<AccessControlRequestMethod, crate::Error> =
FromRequest::from_request(request.inner()); FromRequest::from_request(request.inner());
let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s);
@ -278,7 +279,7 @@ mod tests {
FromStr::from_str("date").unwrap(), FromStr::from_str("date").unwrap(),
]); ]);
request.add_header(headers); request.add_header(headers);
let outcome: request::Outcome<AccessControlRequestHeaders, ::Error> = let outcome: request::Outcome<AccessControlRequestHeaders, crate::Error> =
FromRequest::from_request(request.inner()); FromRequest::from_request(request.inner());
let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s);

View File

@ -591,7 +591,7 @@ use rocket::request::{FromRequest, Request};
use rocket::response; use rocket::response;
use rocket::{Outcome, State}; use rocket::{Outcome, State};
use headers::{ use crate::headers::{
AccessControlRequestHeaders, AccessControlRequestMethod, HeaderFieldName, HeaderFieldNamesSet, AccessControlRequestHeaders, AccessControlRequestMethod, HeaderFieldName, HeaderFieldNamesSet,
Origin, Url, Origin, Url,
}; };
@ -801,7 +801,7 @@ mod method_serde {
use serde::{self, Deserialize, Serialize}; use serde::{self, Deserialize, Serialize};
use Method; use crate::Method;
impl Serialize for Method { impl Serialize for Method {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@ -1917,7 +1917,7 @@ mod tests {
use serde_json; use serde_json;
use super::*; use super::*;
use http::Method; use crate::http::Method;
fn make_cors_options() -> Cors { fn make_cors_options() -> Cors {
let (allowed_origins, failed_origins) = AllowedOrigins::some(&["https://www.acme.com"]); let (allowed_origins, failed_origins) = AllowedOrigins::some(&["https://www.acme.com"]);
@ -2265,7 +2265,7 @@ mod tests {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
struct MethodTest { struct MethodTest {
method: ::Method, method: crate::Method,
} }
#[cfg(feature = "serialization")] #[cfg(feature = "serialization")]