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:
parent
9cb16ba01d
commit
13a3f7368e
|
@ -9,6 +9,7 @@ repository = "https://github.com/lawliet89/rocket_cors"
|
|||
documentation = "https://docs.rs/rocket_cors/"
|
||||
keywords = ["rocket", "cors"]
|
||||
categories = ["web-programming"]
|
||||
edition = "2018"
|
||||
|
||||
[badges]
|
||||
travis-ci = { repository = "lawliet89/rocket_cors" }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
use rocket;
|
||||
use rocket_cors;
|
||||
|
||||
use rocket::http::Method;
|
||||
use rocket::{get, routes};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
use rocket;
|
||||
use rocket_cors;
|
||||
|
||||
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
|
||||
#[get("/")]
|
||||
fn responder(cors: Guard) -> Responder<&str> {
|
||||
fn responder(cors: Guard<'_>) -> Responder<'_, &str> {
|
||||
cors.responder("Hello CORS!")
|
||||
}
|
||||
|
||||
/// Using a `Response` instead of a `Responder`. You generally won't have to do this.
|
||||
#[get("/response")]
|
||||
fn response(cors: Guard) -> Response {
|
||||
fn response(cors: Guard<'_>) -> Response<'_> {
|
||||
let mut response = Response::new();
|
||||
response.set_sized_body(Cursor::new("Hello CORS!"));
|
||||
cors.response(response)
|
||||
|
@ -25,13 +25,13 @@ fn response(cors: Guard) -> Response {
|
|||
|
||||
/// Manually mount an OPTIONS route for your own handling
|
||||
#[options("/manual")]
|
||||
fn manual_options(cors: Guard) -> Responder<&str> {
|
||||
fn manual_options(cors: Guard<'_>) -> Responder<'_, &str> {
|
||||
cors.responder("Manual OPTIONS preflight handling")
|
||||
}
|
||||
|
||||
/// Manually mount an OPTIONS route for your own handling
|
||||
#[get("/manual")]
|
||||
fn manual(cors: Guard) -> Responder<&str> {
|
||||
fn manual(cors: Guard<'_>) -> Responder<'_, &str> {
|
||||
cors.responder("Manual OPTIONS preflight handling")
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
//!
|
||||
//! Note: This requires the `serialization` feature which is enabled by default.
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors as cors;
|
||||
extern crate serde_json;
|
||||
|
||||
use rocket_cors as cors;
|
||||
use serde_json;
|
||||
|
||||
use crate::cors::{AllowedHeaders, AllowedOrigins, Cors};
|
||||
use rocket::http::Method;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
use rocket;
|
||||
use rocket_cors;
|
||||
|
||||
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
|
||||
/// `'r` and so does `Responder`!
|
||||
#[get("/")]
|
||||
fn borrowed(options: State<Cors>) -> impl Responder {
|
||||
fn borrowed(options: State<'_, Cors>) -> impl Responder<'_> {
|
||||
options
|
||||
.inner()
|
||||
.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
|
||||
/// `'r` and so does `Responder`!
|
||||
#[get("/response")]
|
||||
fn response(options: State<Cors>) -> impl Responder {
|
||||
fn response(options: State<'_, Cors>) -> impl Responder<'_> {
|
||||
let mut response = Response::new();
|
||||
response.set_sized_body(Cursor::new("Hello CORS!"));
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
//! `ping` route that you want to allow all Origins to access.
|
||||
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
use rocket;
|
||||
use rocket_cors;
|
||||
|
||||
use rocket::http::Method;
|
||||
use rocket::response::Responder;
|
||||
|
@ -14,7 +14,7 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors, Guard};
|
|||
|
||||
/// The "usual" app route
|
||||
#[get("/")]
|
||||
fn app(cors: Guard) -> rocket_cors::Responder<&str> {
|
||||
fn app(cors: Guard<'_>) -> rocket_cors::Responder<'_, &str> {
|
||||
cors.responder("Hello CORS!")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Fairing implementation
|
||||
|
||||
use log::{error, info, log};
|
||||
use ::log::{error, info, log};
|
||||
use rocket::http::{self, uri::Origin, Status};
|
||||
use rocket::{self, error_, info_, log_, Outcome, Request};
|
||||
|
||||
|
@ -16,7 +16,7 @@ enum CorsValidation {
|
|||
|
||||
/// Route for Fairing error handling
|
||||
pub(crate) fn fairing_error_route<'r>(
|
||||
request: &'r Request,
|
||||
request: &'r Request<'_>,
|
||||
_: rocket::Data,
|
||||
) -> rocket::handler::Outcome<'r> {
|
||||
let status = request
|
||||
|
@ -36,7 +36,7 @@ fn fairing_route(rank: isize) -> rocket::Route {
|
|||
}
|
||||
|
||||
/// 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();
|
||||
|
||||
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(
|
||||
options: &Cors,
|
||||
request: &Request,
|
||||
response: &mut rocket::Response,
|
||||
request: &Request<'_>,
|
||||
response: &mut rocket::Response<'_>,
|
||||
) -> Result<(), Error> {
|
||||
let origin = match origin(request)? {
|
||||
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) {
|
||||
Ok(_) => CorsValidation::Success,
|
||||
Err(err) => {
|
||||
|
@ -126,7 +126,7 @@ impl rocket::fairing::Fairing for Cors {
|
|||
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) {
|
||||
error_!("Fairings on_response error: {}\nMost likely a bug", err);
|
||||
response.set_status(Status::InternalServerError);
|
||||
|
|
|
@ -34,7 +34,7 @@ impl Deref 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)
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ pub type HeaderFieldNamesSet = HashSet<HeaderFieldName>;
|
|||
pub struct Url(#[cfg_attr(feature = "serialization", serde(with = "url_serde"))] url::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)
|
||||
}
|
||||
}
|
||||
|
|
63
src/lib.rs
63
src/lib.rs
|
@ -550,29 +550,6 @@
|
|||
)]
|
||||
#![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)]
|
||||
#[macro_use]
|
||||
mod test_macros;
|
||||
|
@ -588,7 +565,7 @@ use std::marker::PhantomData;
|
|||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
|
||||
use log::{error, info, log};
|
||||
use ::log::{error, info, log};
|
||||
use rocket::http::{self, Status};
|
||||
use rocket::request::{FromRequest, Request};
|
||||
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 {
|
||||
Error::BadOrigin(ref e) => Some(e),
|
||||
_ => Some(self),
|
||||
|
@ -696,7 +673,7 @@ impl error::Error 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 {
|
||||
Error::BadOrigin(ref e) => fmt::Display::fmt(e, f),
|
||||
_ => write!(f, "{}", error::Error::description(self)),
|
||||
|
@ -705,7 +682,7 @@ impl fmt::Display 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);
|
||||
Err(self.status())
|
||||
}
|
||||
|
@ -786,7 +763,7 @@ impl From<http::Method> 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)
|
||||
}
|
||||
}
|
||||
|
@ -820,7 +797,7 @@ mod method_serde {
|
|||
impl<'de> Visitor<'de> for MethodVisitor {
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -1303,7 +1280,7 @@ impl Response {
|
|||
/// Merge CORS headers with an existing `rocket::Response`.
|
||||
///
|
||||
/// 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
|
||||
let origin = match self.allow_origin {
|
||||
None => {
|
||||
|
@ -1426,7 +1403,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
|
|||
type Error = 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,
|
||||
_ => {
|
||||
let error = Error::MissingCorsInRocketState;
|
||||
|
@ -1461,7 +1438,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> {
|
|||
pub struct Responder<'r, R> {
|
||||
responder: R,
|
||||
cors_response: Response,
|
||||
marker: PhantomData<response::Responder<'r>>,
|
||||
marker: PhantomData<dyn response::Responder<'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
|
||||
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?
|
||||
self.cors_response.merge(&mut 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> {
|
||||
fn respond_to(self, request: &Request) -> response::Result<'r> {
|
||||
fn respond_to(self, request: &Request<'_>) -> response::Result<'r> {
|
||||
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)?;
|
||||
Ok(Guard::new(response))
|
||||
}
|
||||
|
@ -1525,7 +1502,7 @@ where
|
|||
F: FnOnce(Guard<'r>) -> R + '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) {
|
||||
Ok(guard) => guard,
|
||||
Err(err) => {
|
||||
|
@ -1554,7 +1531,7 @@ enum ValidationResult {
|
|||
}
|
||||
|
||||
/// 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)?;
|
||||
|
||||
Ok(match result {
|
||||
|
@ -1567,7 +1544,7 @@ fn validate_and_build(options: &Cors, request: &Request) -> Result<Response, Err
|
|||
}
|
||||
|
||||
/// 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.
|
||||
// The request is outside the scope of this specification.
|
||||
let origin = origin(request)?;
|
||||
|
@ -1644,7 +1621,7 @@ fn validate_allowed_headers(
|
|||
}
|
||||
|
||||
/// 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) {
|
||||
Outcome::Forward(()) => Ok(None),
|
||||
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
|
||||
fn request_method(request: &Request) -> Result<Option<AccessControlRequestMethod>, Error> {
|
||||
fn request_method(request: &Request<'_>) -> Result<Option<AccessControlRequestMethod>, Error> {
|
||||
match AccessControlRequestMethod::from_request(request) {
|
||||
Outcome::Forward(()) => Ok(None),
|
||||
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
|
||||
fn request_headers(request: &Request) -> Result<Option<AccessControlRequestHeaders>, Error> {
|
||||
fn request_headers(request: &Request<'_>) -> Result<Option<AccessControlRequestHeaders>, Error> {
|
||||
match AccessControlRequestHeaders::from_request(request) {
|
||||
Outcome::Forward(()) => Ok(None),
|
||||
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"
|
||||
fn catch_all_options_route_handler<'r>(
|
||||
request: &'r Request,
|
||||
request: &'r Request<'_>,
|
||||
_: rocket::Data,
|
||||
) -> rocket::handler::Outcome<'r> {
|
||||
let guard: Guard = match request.guard() {
|
||||
let guard: Guard<'_> = match request.guard() {
|
||||
Outcome::Success(guard) => guard,
|
||||
Outcome::Failure((status, _)) => return rocket::handler::Outcome::failure(status),
|
||||
Outcome::Forward(()) => unreachable!("Should not be reachable"),
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
//! This crate tests using `rocket_cors` using Fairings
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate hyper;
|
||||
use hyper;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! This crate tests using `rocket_cors` using the per-route handling with request guard
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate hyper;
|
||||
use hyper;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors as cors;
|
||||
use rocket_cors as cors;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -13,42 +13,42 @@ use rocket::local::Client;
|
|||
use rocket::{Response, State};
|
||||
|
||||
#[get("/")]
|
||||
fn cors(cors: cors::Guard) -> cors::Responder<&str> {
|
||||
fn cors(cors: cors::Guard<'_>) -> cors::Responder<'_, &str> {
|
||||
cors.responder("Hello CORS")
|
||||
}
|
||||
|
||||
#[get("/panic")]
|
||||
fn panicking_route(_cors: cors::Guard) {
|
||||
fn panicking_route(_cors: cors::Guard<'_>) {
|
||||
panic!("This route will panic");
|
||||
}
|
||||
|
||||
/// Manually specify our own OPTIONS route
|
||||
#[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")
|
||||
}
|
||||
|
||||
/// Manually specify our own OPTIONS route
|
||||
#[get("/manual")]
|
||||
fn cors_manual(cors: cors::Guard) -> cors::Responder<&str> {
|
||||
fn cors_manual(cors: cors::Guard<'_>) -> cors::Responder<'_, &str> {
|
||||
cors.responder("Hello CORS")
|
||||
}
|
||||
|
||||
/// Using a `Response` instead of a `Responder`
|
||||
#[get("/response")]
|
||||
fn response(cors: cors::Guard) -> Response {
|
||||
fn response(cors: cors::Guard<'_>) -> Response<'_> {
|
||||
cors.response(Response::new())
|
||||
}
|
||||
|
||||
/// `Responder` with 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())
|
||||
}
|
||||
|
||||
/// `Responder` with 'static ()
|
||||
#[get("/responder/unit")]
|
||||
fn responder_unit(cors: cors::Guard) -> cors::Responder<()> {
|
||||
fn responder_unit(cors: cors::Guard<'_>) -> cors::Responder<'_, ()> {
|
||||
cors.responder(())
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
//! This crate tests that all the request headers are parsed correctly in the round trip
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate hyper;
|
||||
use hyper;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
//! This crate tests using `rocket_cors` using manual mode
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate hyper;
|
||||
use hyper;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -16,14 +15,14 @@ use rocket_cors::*;
|
|||
|
||||
/// Using a borrowed `Cors`
|
||||
#[get("/")]
|
||||
fn cors(options: State<Cors>) -> impl Responder {
|
||||
fn cors(options: State<'_, Cors>) -> impl Responder<'_> {
|
||||
options
|
||||
.inner()
|
||||
.respond_borrowed(|guard| guard.responder("Hello CORS"))
|
||||
}
|
||||
|
||||
#[get("/panic")]
|
||||
fn panicking_route(options: State<Cors>) -> impl Responder {
|
||||
fn panicking_route(options: State<'_, Cors>) -> impl Responder<'_> {
|
||||
options.inner().respond_borrowed(|_| -> () {
|
||||
panic!("This route will panic");
|
||||
})
|
||||
|
@ -49,7 +48,7 @@ fn owned<'r>() -> impl Responder<'r> {
|
|||
|
||||
/// `Responder` with String
|
||||
#[get("/")]
|
||||
fn responder_string(options: State<Cors>) -> impl Responder {
|
||||
fn responder_string(options: State<'_, Cors>) -> impl Responder<'_> {
|
||||
options
|
||||
.inner()
|
||||
.respond_borrowed(|guard| guard.responder("Hello CORS".to_string()))
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
//! 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.
|
||||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
extern crate hyper;
|
||||
use hyper;
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
extern crate rocket_cors;
|
||||
use rocket_cors;
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
@ -18,7 +18,7 @@ use rocket_cors::{AllowedHeaders, AllowedOrigins, Cors, Guard};
|
|||
|
||||
/// The "usual" app route
|
||||
#[get("/")]
|
||||
fn app(cors: Guard) -> rocket_cors::Responder<&str> {
|
||||
fn app(cors: Guard<'_>) -> rocket_cors::Responder<'_, &str> {
|
||||
cors.responder("Hello CORS!")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue