From 086f018bb98a94ac1a042dd68039cac0e90fdae1 Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Wed, 31 Oct 2018 10:30:58 +0800 Subject: [PATCH] cargo fix --edition --- examples/json.rs | 2 +- src/fairing.rs | 6 ++++-- src/headers.rs | 31 ++++++++++++++++--------------- src/lib.rs | 8 ++++---- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/examples/json.rs b/examples/json.rs index b19bb95..c1bfd94 100644 --- a/examples/json.rs +++ b/examples/json.rs @@ -6,7 +6,7 @@ extern crate rocket; extern crate rocket_cors as cors; extern crate serde_json; -use cors::{AllowedHeaders, AllowedOrigins, Cors}; +use crate::cors::{AllowedHeaders, AllowedOrigins, Cors}; use rocket::http::Method; fn main() { diff --git a/src/fairing.rs b/src/fairing.rs index 47b97b0..ebebcdb 100644 --- a/src/fairing.rs +++ b/src/fairing.rs @@ -4,7 +4,9 @@ use std::str::FromStr; use rocket::http::{self, uri::Origin, Header, Status}; 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 static CORS_HEADER: &str = "ROCKET-CORS"; @@ -176,7 +178,7 @@ mod tests { use rocket::local::Client; use rocket::Rocket; - use {AllOrSome, AllowedHeaders, AllowedOrigins, Cors}; + use crate::{AllOrSome, AllowedHeaders, AllowedOrigins, Cors}; const CORS_ROOT: &'static str = "/my_cors"; diff --git a/src/headers.rs b/src/headers.rs index 22f34cc..3792bba 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -89,13 +89,13 @@ impl FromStr 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 { + fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome { match request.headers().get_one("Origin") { Some(origin) => match Self::from_str(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(()), } @@ -113,24 +113,24 @@ pub type Origin = Url; /// 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. #[derive(Debug)] -pub struct AccessControlRequestMethod(pub ::Method); +pub struct AccessControlRequestMethod(pub crate::Method); impl FromStr for AccessControlRequestMethod { type Err = (); fn from_str(method: &str) -> Result { - Ok(AccessControlRequestMethod(::Method::from_str(method)?)) + Ok(AccessControlRequestMethod(crate::Method::from_str(method)?)) } } 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 { + fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome { match request.headers().get_one("Access-Control-Request-Method") { Some(request_method) => match Self::from_str(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(()), } @@ -163,9 +163,9 @@ impl FromStr 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 { + fn from_request(request: &'a rocket::Request<'r>) -> request::Outcome { match request.headers().get_one("Access-Control-Request-Headers") { Some(request_headers) => match Self::from_str(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); request.add_header(origin); - let outcome: request::Outcome = FromRequest::from_request(request.inner()); + let outcome: request::Outcome = + FromRequest::from_request(request.inner()); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); 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)); assert_matches!( parsed_method, - AccessControlRequestMethod(::Method(rocket::http::Method::Post)) + AccessControlRequestMethod(crate::Method(rocket::http::Method::Post)) ); let method = "options"; let parsed_method = not_err!(AccessControlRequestMethod::from_str(method)); assert_matches!( parsed_method, - AccessControlRequestMethod(::Method(rocket::http::Method::Options)) + AccessControlRequestMethod(crate::Method(rocket::http::Method::Options)) ); let method = "INVALID"; @@ -251,7 +252,7 @@ mod tests { let mut request = client.get("/"); let method = hyper::header::AccessControlRequestMethod(hyper::method::Method::Get); request.add_header(method); - let outcome: request::Outcome = + let outcome: request::Outcome = FromRequest::from_request(request.inner()); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); @@ -278,7 +279,7 @@ mod tests { FromStr::from_str("date").unwrap(), ]); request.add_header(headers); - let outcome: request::Outcome = + let outcome: request::Outcome = FromRequest::from_request(request.inner()); let parsed_header = assert_matches!(outcome, Outcome::Success(s), s); diff --git a/src/lib.rs b/src/lib.rs index 94a3239..da46507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -591,7 +591,7 @@ use rocket::request::{FromRequest, Request}; use rocket::response; use rocket::{Outcome, State}; -use headers::{ +use crate::headers::{ AccessControlRequestHeaders, AccessControlRequestMethod, HeaderFieldName, HeaderFieldNamesSet, Origin, Url, }; @@ -801,7 +801,7 @@ mod method_serde { use serde::{self, Deserialize, Serialize}; - use Method; + use crate::Method; impl Serialize for Method { fn serialize(&self, serializer: S) -> Result @@ -1917,7 +1917,7 @@ mod tests { use serde_json; use super::*; - use http::Method; + use crate::http::Method; fn make_cors_options() -> Cors { let (allowed_origins, failed_origins) = AllowedOrigins::some(&["https://www.acme.com"]); @@ -2265,7 +2265,7 @@ mod tests { #[derive(Debug, PartialEq)] #[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))] struct MethodTest { - method: ::Method, + method: crate::Method, } #[cfg(feature = "serialization")]