Upgrade to Rust 2018 to fix Macro use and import issues (#52)

* Upgrade to Rust 2018 to fix Macro use and import issues

Fixes #51

* Cargo fmt
This commit is contained in:
Yong Wen Chua 2018-11-21 12:17:40 +08:00 committed by GitHub
parent 9cb16ba01d
commit 13a3f7368e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 66 additions and 91 deletions

View File

@ -9,6 +9,7 @@ repository = "https://github.com/lawliet89/rocket_cors"
documentation = "https://docs.rs/rocket_cors/" documentation = "https://docs.rs/rocket_cors/"
keywords = ["rocket", "cors"] keywords = ["rocket", "cors"]
categories = ["web-programming"] categories = ["web-programming"]
edition = "2018"
[badges] [badges]
travis-ci = { repository = "lawliet89/rocket_cors" } travis-ci = { repository = "lawliet89/rocket_cors" }

View File

@ -1,6 +1,6 @@
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket; use rocket;
extern crate rocket_cors; use rocket_cors;
use rocket::http::Method; use rocket::http::Method;
use rocket::{get, routes}; use rocket::{get, routes};

View File

@ -1,6 +1,6 @@
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket; use rocket;
extern crate rocket_cors; use rocket_cors;
use std::io::Cursor; use std::io::Cursor;
@ -11,13 +11,13 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Guard, Responder};
/// Using a `Responder` -- the usual way you would use this /// Using a `Responder` -- the usual way you would use this
#[get("/")] #[get("/")]
fn responder(cors: Guard) -> Responder<&str> { fn responder(cors: Guard<'_>) -> Responder<'_, &str> {
cors.responder("Hello CORS!") cors.responder("Hello CORS!")
} }
/// Using a `Response` instead of a `Responder`. You generally won't have to do this. /// Using a `Response` instead of a `Responder`. You generally won't have to do this.
#[get("/response")] #[get("/response")]
fn response(cors: Guard) -> Response { fn response(cors: Guard<'_>) -> Response<'_> {
let mut response = Response::new(); let mut response = Response::new();
response.set_sized_body(Cursor::new("Hello CORS!")); response.set_sized_body(Cursor::new("Hello CORS!"));
cors.response(response) cors.response(response)
@ -25,13 +25,13 @@ fn response(cors: Guard) -> Response {
/// Manually mount an OPTIONS route for your own handling /// Manually mount an OPTIONS route for your own handling
#[options("/manual")] #[options("/manual")]
fn manual_options(cors: Guard) -> Responder<&str> { fn manual_options(cors: Guard<'_>) -> Responder<'_, &str> {
cors.responder("Manual OPTIONS preflight handling") cors.responder("Manual OPTIONS preflight handling")
} }
/// Manually mount an OPTIONS route for your own handling /// Manually mount an OPTIONS route for your own handling
#[get("/manual")] #[get("/manual")]
fn manual(cors: Guard) -> Responder<&str> { fn manual(cors: Guard<'_>) -> Responder<'_, &str> {
cors.responder("Manual OPTIONS preflight handling") cors.responder("Manual OPTIONS preflight handling")
} }

View File

@ -2,9 +2,9 @@
//! //!
//! Note: This requires the `serialization` feature which is enabled by default. //! Note: This requires the `serialization` feature which is enabled by default.
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket;
extern crate rocket_cors as cors; use rocket_cors as cors;
extern crate serde_json; use serde_json;
use crate::cors::{AllowedHeaders, AllowedOrigins, Cors}; use crate::cors::{AllowedHeaders, AllowedOrigins, Cors};
use rocket::http::Method; use rocket::http::Method;

View File

@ -1,6 +1,6 @@
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket; use rocket;
extern crate rocket_cors; use rocket_cors;
use std::io::Cursor; use std::io::Cursor;
@ -13,7 +13,7 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors};
/// Note that the `'r` lifetime annotation is not requred here because `State` borrows with lifetime /// Note that the `'r` lifetime annotation is not requred here because `State` borrows with lifetime
/// `'r` and so does `Responder`! /// `'r` and so does `Responder`!
#[get("/")] #[get("/")]
fn borrowed(options: State<Cors>) -> impl Responder { fn borrowed(options: State<'_, Cors>) -> impl Responder<'_> {
options options
.inner() .inner()
.respond_borrowed(|guard| guard.responder("Hello CORS")) .respond_borrowed(|guard| guard.responder("Hello CORS"))
@ -23,7 +23,7 @@ fn borrowed(options: State<Cors>) -> impl Responder {
/// Note that the `'r` lifetime annotation is not requred here because `State` borrows with lifetime /// Note that the `'r` lifetime annotation is not requred here because `State` borrows with lifetime
/// `'r` and so does `Responder`! /// `'r` and so does `Responder`!
#[get("/response")] #[get("/response")]
fn response(options: State<Cors>) -> impl Responder { fn response(options: State<'_, Cors>) -> impl Responder<'_> {
let mut response = Response::new(); let mut response = Response::new();
response.set_sized_body(Cursor::new("Hello CORS!")); response.set_sized_body(Cursor::new("Hello CORS!"));

View File

@ -4,8 +4,8 @@
//! `ping` route that you want to allow all Origins to access. //! `ping` route that you want to allow all Origins to access.
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket; use rocket;
extern crate rocket_cors; use rocket_cors;
use rocket::http::Method; use rocket::http::Method;
use rocket::response::Responder; use rocket::response::Responder;
@ -14,7 +14,7 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors, Guard};
/// The "usual" app route /// The "usual" app route
#[get("/")] #[get("/")]
fn app(cors: Guard) -> rocket_cors::Responder<&str> { fn app(cors: Guard<'_>) -> rocket_cors::Responder<'_, &str> {
cors.responder("Hello CORS!") cors.responder("Hello CORS!")
} }

View File

@ -1,6 +1,6 @@
//! Fairing implementation //! Fairing implementation
use log::{error, info, log}; use ::log::{error, info, log};
use rocket::http::{self, uri::Origin, Status}; use rocket::http::{self, uri::Origin, Status};
use rocket::{self, error_, info_, log_, Outcome, Request}; use rocket::{self, error_, info_, log_, Outcome, Request};
@ -16,7 +16,7 @@ enum CorsValidation {
/// Route for Fairing error handling /// Route for Fairing error handling
pub(crate) fn fairing_error_route<'r>( pub(crate) fn fairing_error_route<'r>(
request: &'r Request, request: &'r Request<'_>,
_: rocket::Data, _: rocket::Data,
) -> rocket::handler::Outcome<'r> { ) -> rocket::handler::Outcome<'r> {
let status = request let status = request
@ -36,7 +36,7 @@ fn fairing_route(rank: isize) -> rocket::Route {
} }
/// Modifies a `Request` to route to Fairing error handler /// Modifies a `Request` to route to Fairing error handler
fn route_to_fairing_error_handler(options: &Cors, status: u16, request: &mut Request) { fn route_to_fairing_error_handler(options: &Cors, status: u16, request: &mut Request<'_>) {
let origin = Origin::parse_owned(format!("{}/{}", options.fairing_route_base, status)).unwrap(); let origin = Origin::parse_owned(format!("{}/{}", options.fairing_route_base, status)).unwrap();
request.set_method(http::Method::Get); request.set_method(http::Method::Get);
@ -45,8 +45,8 @@ fn route_to_fairing_error_handler(options: &Cors, status: u16, request: &mut Req
fn on_response_wrapper( fn on_response_wrapper(
options: &Cors, options: &Cors,
request: &Request, request: &Request<'_>,
response: &mut rocket::Response, response: &mut rocket::Response<'_>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let origin = match origin(request)? { let origin = match origin(request)? {
None => { None => {
@ -112,7 +112,7 @@ impl rocket::fairing::Fairing for Cors {
} }
} }
fn on_request(&self, request: &mut Request, _: &rocket::Data) { fn on_request(&self, request: &mut Request<'_>, _: &rocket::Data) {
let result = match validate(self, request) { let result = match validate(self, request) {
Ok(_) => CorsValidation::Success, Ok(_) => CorsValidation::Success,
Err(err) => { Err(err) => {
@ -126,7 +126,7 @@ impl rocket::fairing::Fairing for Cors {
let _ = request.local_cache(|| result); let _ = request.local_cache(|| result);
} }
fn on_response(&self, request: &Request, response: &mut rocket::Response) { fn on_response(&self, request: &Request<'_>, response: &mut rocket::Response<'_>) {
if let Err(err) = on_response_wrapper(self, request, response) { if let Err(err) = on_response_wrapper(self, request, response) {
error_!("Fairings on_response error: {}\nMost likely a bug", err); error_!("Fairings on_response error: {}\nMost likely a bug", err);
response.set_status(Status::InternalServerError); response.set_status(Status::InternalServerError);

View File

@ -34,7 +34,7 @@ impl Deref for HeaderFieldName {
} }
impl fmt::Display for HeaderFieldName { impl fmt::Display for HeaderFieldName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f) self.0.fmt(f)
} }
} }
@ -68,7 +68,7 @@ pub type HeaderFieldNamesSet = HashSet<HeaderFieldName>;
pub struct Url(#[cfg_attr(feature = "serialization", serde(with = "url_serde"))] url::Url); pub struct Url(#[cfg_attr(feature = "serialization", serde(with = "url_serde"))] url::Url);
impl fmt::Display for Url { impl fmt::Display for Url {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f) self.0.fmt(f)
} }
} }

View File

@ -550,29 +550,6 @@
)] )]
#![doc(test(attr(allow(unused_variables), deny(warnings))))] #![doc(test(attr(allow(unused_variables), deny(warnings))))]
extern crate log;
extern crate rocket;
extern crate unicase;
extern crate url;
#[cfg(feature = "serialization")]
extern crate serde;
#[cfg(feature = "serialization")]
extern crate serde_derive;
#[cfg(feature = "serialization")]
extern crate unicase_serde;
#[cfg(feature = "serialization")]
extern crate url_serde;
#[cfg(test)]
extern crate hyper;
#[cfg(feature = "serialization")]
#[cfg(test)]
extern crate serde_json;
#[cfg(feature = "serialization")]
#[cfg(test)]
extern crate serde_test;
#[cfg(test)] #[cfg(test)]
#[macro_use] #[macro_use]
mod test_macros; mod test_macros;
@ -588,7 +565,7 @@ use std::marker::PhantomData;
use std::ops::Deref; use std::ops::Deref;
use std::str::FromStr; use std::str::FromStr;
use log::{error, info, log}; use ::log::{error, info, log};
use rocket::http::{self, Status}; use rocket::http::{self, Status};
use rocket::request::{FromRequest, Request}; use rocket::request::{FromRequest, Request};
use rocket::response; use rocket::response;
@ -687,7 +664,7 @@ impl error::Error for Error {
} }
} }
fn cause(&self) -> Option<&error::Error> { fn cause(&self) -> Option<&dyn error::Error> {
match *self { match *self {
Error::BadOrigin(ref e) => Some(e), Error::BadOrigin(ref e) => Some(e),
_ => Some(self), _ => Some(self),
@ -696,7 +673,7 @@ impl error::Error for Error {
} }
impl fmt::Display for Error { impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
Error::BadOrigin(ref e) => fmt::Display::fmt(e, f), Error::BadOrigin(ref e) => fmt::Display::fmt(e, f),
_ => write!(f, "{}", error::Error::description(self)), _ => write!(f, "{}", error::Error::description(self)),
@ -705,7 +682,7 @@ impl fmt::Display for Error {
} }
impl<'r> response::Responder<'r> for Error { impl<'r> response::Responder<'r> for Error {
fn respond_to(self, _: &Request) -> Result<response::Response<'r>, Status> { fn respond_to(self, _: &Request<'_>) -> Result<response::Response<'r>, Status> {
error_!("CORS Error: {}", self); error_!("CORS Error: {}", self);
Err(self.status()) Err(self.status())
} }
@ -786,7 +763,7 @@ impl From<http::Method> for Method {
} }
impl fmt::Display for Method { impl fmt::Display for Method {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f) fmt::Display::fmt(&self.0, f)
} }
} }
@ -820,7 +797,7 @@ mod method_serde {
impl<'de> Visitor<'de> for MethodVisitor { impl<'de> Visitor<'de> for MethodVisitor {
type Value = Method; type Value = Method;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("a string containing a HTTP Verb") formatter.write_str("a string containing a HTTP Verb")
} }
@ -1303,7 +1280,7 @@ impl Response {
/// Merge CORS headers with an existing `rocket::Response`. /// Merge CORS headers with an existing `rocket::Response`.
/// ///
/// This will overwrite any existing CORS headers /// This will overwrite any existing CORS headers
fn merge(&self, response: &mut response::Response) { fn merge(&self, response: &mut response::Response<'_>) {
// TODO: We should be able to remove this // TODO: We should be able to remove this
let origin = match self.allow_origin { let origin = match self.allow_origin {
None => { None => {
@ -1426,7 +1403,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
type Error = Error; type Error = Error;
fn from_request(request: &'a Request<'r>) -> rocket::request::Outcome<Self, Self::Error> { fn from_request(request: &'a Request<'r>) -> rocket::request::Outcome<Self, Self::Error> {
let options = match request.guard::<State<Cors>>() { let options = match request.guard::<State<'_, Cors>>() {
Outcome::Success(options) => options, Outcome::Success(options) => options,
_ => { _ => {
let error = Error::MissingCorsInRocketState; let error = Error::MissingCorsInRocketState;
@ -1461,7 +1438,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
pub struct Responder<'r, R> { pub struct Responder<'r, R> {
responder: R, responder: R,
cors_response: Response, cors_response: Response,
marker: PhantomData<response::Responder<'r>>, marker: PhantomData<dyn response::Responder<'r>>,
} }
impl<'r, R: response::Responder<'r>> Responder<'r, R> { impl<'r, R: response::Responder<'r>> Responder<'r, R> {
@ -1474,7 +1451,7 @@ impl<'r, R: response::Responder<'r>> Responder<'r, R> {
} }
/// Respond to a request /// Respond to a request
fn respond(self, request: &Request) -> response::Result<'r> { fn respond(self, request: &Request<'_>) -> response::Result<'r> {
let mut response = self.responder.respond_to(request)?; // handle status errors? let mut response = self.responder.respond_to(request)?; // handle status errors?
self.cors_response.merge(&mut response); self.cors_response.merge(&mut response);
Ok(response) Ok(response)
@ -1482,7 +1459,7 @@ impl<'r, R: response::Responder<'r>> Responder<'r, R> {
} }
impl<'r, R: response::Responder<'r>> response::Responder<'r> for Responder<'r, R> { impl<'r, R: response::Responder<'r>> response::Responder<'r> for Responder<'r, R> {
fn respond_to(self, request: &Request) -> response::Result<'r> { fn respond_to(self, request: &Request<'_>) -> response::Result<'r> {
self.respond(request) self.respond(request)
} }
} }
@ -1514,7 +1491,7 @@ where
} }
} }
fn build_guard(&self, request: &Request) -> Result<Guard<'r>, Error> { fn build_guard(&self, request: &Request<'_>) -> Result<Guard<'r>, Error> {
let response = Response::validate_and_build(&self.options, request)?; let response = Response::validate_and_build(&self.options, request)?;
Ok(Guard::new(response)) Ok(Guard::new(response))
} }
@ -1525,7 +1502,7 @@ where
F: FnOnce(Guard<'r>) -> R + 'r, F: FnOnce(Guard<'r>) -> R + 'r,
R: response::Responder<'r>, R: response::Responder<'r>,
{ {
fn respond_to(self, request: &Request) -> response::Result<'r> { fn respond_to(self, request: &Request<'_>) -> response::Result<'r> {
let guard = match self.build_guard(request) { let guard = match self.build_guard(request) {
Ok(guard) => guard, Ok(guard) => guard,
Err(err) => { Err(err) => {
@ -1554,7 +1531,7 @@ enum ValidationResult {
} }
/// Validates a request for CORS and returns a CORS Response /// Validates a request for CORS and returns a CORS Response
fn validate_and_build(options: &Cors, request: &Request) -> Result<Response, Error> { fn validate_and_build(options: &Cors, request: &Request<'_>) -> Result<Response, Error> {
let result = validate(options, request)?; let result = validate(options, request)?;
Ok(match result { Ok(match result {
@ -1567,7 +1544,7 @@ fn validate_and_build(options: &Cors, request: &Request) -> Result<Response, Err
} }
/// Validate a CORS request /// Validate a CORS request
fn validate(options: &Cors, request: &Request) -> Result<ValidationResult, Error> { fn validate(options: &Cors, request: &Request<'_>) -> Result<ValidationResult, Error> {
// 1. If the Origin header is not present terminate this set of steps. // 1. If the Origin header is not present terminate this set of steps.
// The request is outside the scope of this specification. // The request is outside the scope of this specification.
let origin = origin(request)?; let origin = origin(request)?;
@ -1644,7 +1621,7 @@ fn validate_allowed_headers(
} }
/// Gets the `Origin` request header from the request /// Gets the `Origin` request header from the request
fn origin(request: &Request) -> Result<Option<Origin>, Error> { fn origin(request: &Request<'_>) -> Result<Option<Origin>, Error> {
match Origin::from_request(request) { match Origin::from_request(request) {
Outcome::Forward(()) => Ok(None), Outcome::Forward(()) => Ok(None),
Outcome::Success(origin) => Ok(Some(origin)), Outcome::Success(origin) => Ok(Some(origin)),
@ -1653,7 +1630,7 @@ fn origin(request: &Request) -> Result<Option<Origin>, Error> {
} }
/// Gets the `Access-Control-Request-Method` request header from the request /// Gets the `Access-Control-Request-Method` request header from the request
fn request_method(request: &Request) -> Result<Option<AccessControlRequestMethod>, Error> { fn request_method(request: &Request<'_>) -> Result<Option<AccessControlRequestMethod>, Error> {
match AccessControlRequestMethod::from_request(request) { match AccessControlRequestMethod::from_request(request) {
Outcome::Forward(()) => Ok(None), Outcome::Forward(()) => Ok(None),
Outcome::Success(method) => Ok(Some(method)), Outcome::Success(method) => Ok(Some(method)),
@ -1662,7 +1639,7 @@ fn request_method(request: &Request) -> Result<Option<AccessControlRequestMethod
} }
/// Gets the `Access-Control-Request-Headers` request header from the request /// Gets the `Access-Control-Request-Headers` request header from the request
fn request_headers(request: &Request) -> Result<Option<AccessControlRequestHeaders>, Error> { fn request_headers(request: &Request<'_>) -> Result<Option<AccessControlRequestHeaders>, Error> {
match AccessControlRequestHeaders::from_request(request) { match AccessControlRequestHeaders::from_request(request) {
Outcome::Forward(()) => Ok(None), Outcome::Forward(()) => Ok(None),
Outcome::Success(geaders) => Ok(Some(geaders)), Outcome::Success(geaders) => Ok(Some(geaders)),
@ -1887,10 +1864,10 @@ pub fn catch_all_options_routes() -> Vec<rocket::Route> {
/// Handler for the "catch all options route" /// Handler for the "catch all options route"
fn catch_all_options_route_handler<'r>( fn catch_all_options_route_handler<'r>(
request: &'r Request, request: &'r Request<'_>,
_: rocket::Data, _: rocket::Data,
) -> rocket::handler::Outcome<'r> { ) -> rocket::handler::Outcome<'r> {
let guard: Guard = match request.guard() { let guard: Guard<'_> = match request.guard() {
Outcome::Success(guard) => guard, Outcome::Success(guard) => guard,
Outcome::Failure((status, _)) => return rocket::handler::Outcome::failure(status), Outcome::Failure((status, _)) => return rocket::handler::Outcome::failure(status),
Outcome::Forward(()) => unreachable!("Should not be reachable"), Outcome::Forward(()) => unreachable!("Should not be reachable"),

View File

@ -1,9 +1,8 @@
//! This crate tests using `rocket_cors` using Fairings //! This crate tests using `rocket_cors` using Fairings
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper; use hyper;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_cors;
use std::str::FromStr; use std::str::FromStr;

View File

@ -1,9 +1,9 @@
//! This crate tests using `rocket_cors` using the per-route handling with request guard //! This crate tests using `rocket_cors` using the per-route handling with request guard
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper; use hyper;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_cors as cors; use rocket_cors as cors;
use std::str::FromStr; use std::str::FromStr;
@ -13,42 +13,42 @@ use rocket::local::Client;
use rocket::{Response, State}; use rocket::{Response, State};
#[get("/")] #[get("/")]
fn cors(cors: cors::Guard) -> cors::Responder<&str> { fn cors(cors: cors::Guard<'_>) -> cors::Responder<'_, &str> {
cors.responder("Hello CORS") cors.responder("Hello CORS")
} }
#[get("/panic")] #[get("/panic")]
fn panicking_route(_cors: cors::Guard) { fn panicking_route(_cors: cors::Guard<'_>) {
panic!("This route will panic"); panic!("This route will panic");
} }
/// Manually specify our own OPTIONS route /// Manually specify our own OPTIONS route
#[options("/manual")] #[options("/manual")]
fn cors_manual_options(cors: cors::Guard) -> cors::Responder<&str> { fn cors_manual_options(cors: cors::Guard<'_>) -> cors::Responder<'_, &str> {
cors.responder("Manual CORS Preflight") cors.responder("Manual CORS Preflight")
} }
/// Manually specify our own OPTIONS route /// Manually specify our own OPTIONS route
#[get("/manual")] #[get("/manual")]
fn cors_manual(cors: cors::Guard) -> cors::Responder<&str> { fn cors_manual(cors: cors::Guard<'_>) -> cors::Responder<'_, &str> {
cors.responder("Hello CORS") cors.responder("Hello CORS")
} }
/// Using a `Response` instead of a `Responder` /// Using a `Response` instead of a `Responder`
#[get("/response")] #[get("/response")]
fn response(cors: cors::Guard) -> Response { fn response(cors: cors::Guard<'_>) -> Response<'_> {
cors.response(Response::new()) cors.response(Response::new())
} }
/// `Responder` with String /// `Responder` with String
#[get("/responder/string")] #[get("/responder/string")]
fn responder_string(cors: cors::Guard) -> cors::Responder<String> { fn responder_string(cors: cors::Guard<'_>) -> cors::Responder<'_, String> {
cors.responder("Hello CORS".to_string()) cors.responder("Hello CORS".to_string())
} }
/// `Responder` with 'static () /// `Responder` with 'static ()
#[get("/responder/unit")] #[get("/responder/unit")]
fn responder_unit(cors: cors::Guard) -> cors::Responder<()> { fn responder_unit(cors: cors::Guard<'_>) -> cors::Responder<'_, ()> {
cors.responder(()) cors.responder(())
} }

View File

@ -1,9 +1,8 @@
//! This crate tests that all the request headers are parsed correctly in the round trip //! This crate tests that all the request headers are parsed correctly in the round trip
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper; use hyper;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_cors;
use std::ops::Deref; use std::ops::Deref;
use std::str::FromStr; use std::str::FromStr;

View File

@ -1,9 +1,8 @@
//! This crate tests using `rocket_cors` using manual mode //! This crate tests using `rocket_cors` using manual mode
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper; use hyper;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_cors;
use std::str::FromStr; use std::str::FromStr;
@ -16,14 +15,14 @@ use rocket_cors::*;
/// Using a borrowed `Cors` /// Using a borrowed `Cors`
#[get("/")] #[get("/")]
fn cors(options: State<Cors>) -> impl Responder { fn cors(options: State<'_, Cors>) -> impl Responder<'_> {
options options
.inner() .inner()
.respond_borrowed(|guard| guard.responder("Hello CORS")) .respond_borrowed(|guard| guard.responder("Hello CORS"))
} }
#[get("/panic")] #[get("/panic")]
fn panicking_route(options: State<Cors>) -> impl Responder { fn panicking_route(options: State<'_, Cors>) -> impl Responder<'_> {
options.inner().respond_borrowed(|_| -> () { options.inner().respond_borrowed(|_| -> () {
panic!("This route will panic"); panic!("This route will panic");
}) })
@ -49,7 +48,7 @@ fn owned<'r>() -> impl Responder<'r> {
/// `Responder` with String /// `Responder` with String
#[get("/")] #[get("/")]
fn responder_string(options: State<Cors>) -> impl Responder { fn responder_string(options: State<'_, Cors>) -> impl Responder<'_> {
options options
.inner() .inner()
.respond_borrowed(|guard| guard.responder("Hello CORS".to_string())) .respond_borrowed(|guard| guard.responder("Hello CORS".to_string()))

View File

@ -3,10 +3,10 @@
//! In this example, you typically have an application wide `Cors` struct except for one specific //! In this example, you typically have an application wide `Cors` struct except for one specific
//! `ping` route that you want to allow all Origins to access. //! `ping` route that you want to allow all Origins to access.
#![feature(proc_macro_hygiene, decl_macro)] #![feature(proc_macro_hygiene, decl_macro)]
extern crate hyper; use hyper;
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
extern crate rocket_cors; use rocket_cors;
use std::str::FromStr; use std::str::FromStr;
@ -18,7 +18,7 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors, Guard};
/// The "usual" app route /// The "usual" app route
#[get("/")] #[get("/")]
fn app(cors: Guard) -> rocket_cors::Responder<&str> { fn app(cors: Guard<'_>) -> rocket_cors::Responder<'_, &str> {
cors.responder("Hello CORS!") cors.responder("Hello CORS!")
} }