Fix build issues for Rocket 0.4.2 (#70)

- Fix clippy lints
- Bump minimum Rust version beyond Rocket required for
  - `std::mem::MaybeUninit` (cf. https://github.com/rust-lang/rust/pull/60445)
  - `alloc` crate
This commit is contained in:
Yong Wen Chua 2019-11-13 10:45:06 +08:00 committed by GitHub
parent c75dcb286d
commit 3a9b1fd7e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 18 deletions

View File

@ -2,8 +2,7 @@ sudo: false
language: rust language: rust
rust: rust:
- nightly - nightly
# Minimum Rust set by Rocket - nightly-2019-05-21 # Minimum supported
- nightly-2018-11-25
branches: branches:
only: only:
- master - master

View File

@ -1,5 +1,12 @@
# CHANGELOG # CHANGELOG
## 0.5.1 (2019-11-13)
There are no new features.
- Fix build issues with Rocket 0.4.2
- Fix clippy lints with latest nightly
## <a name="0.5.0"></a>0.5.0 (2019-05-27) ## <a name="0.5.0"></a>0.5.0 (2019-05-27)
There is no change since `0.5.0-beta1`. There is no change since `0.5.0-beta1`.

View File

@ -1,6 +1,6 @@
[package] [package]
name = "rocket_cors" name = "rocket_cors"
version = "0.5.0" version = "0.5.1"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
authors = ["Yong Wen Chua <me@yongwen.xyz>"] authors = ["Yong Wen Chua <me@yongwen.xyz>"]
description = "Cross-origin resource sharing (CORS) for Rocket.rs applications" description = "Cross-origin resource sharing (CORS) for Rocket.rs applications"
@ -22,7 +22,7 @@ serialization = ["serde", "serde_derive", "unicase_serde"]
[dependencies] [dependencies]
regex = "1.1" regex = "1.1"
rocket = { version = "0.4.0", default-features = false } rocket = { version = "0.4.2", default-features = false }
log = "0.3" log = "0.3"
unicase = "2.0" unicase = "2.0"
url = "1.7.2" url = "1.7.2"

View File

@ -15,6 +15,9 @@ Cross-origin resource sharing (CORS) for [Rocket](https://rocket.rs/) applicatio
If you are using Rocket 0.3, use the `0.3.0` version of this crate. If you are using Rocket 0.3, use the `0.3.0` version of this crate.
There is a minimum version of Rust nightly required. This is usually higher than whatever
Rocket requires plus more if the dependent crates require other features.
### Nightly Rust ### Nightly Rust
Rocket requires nightly Rust. You should probably install Rust with Rocket requires nightly Rust. You should probably install Rust with
@ -30,7 +33,7 @@ work, but they are subject to the minimum that Rocket sets.
Add the following to Cargo.toml: Add the following to Cargo.toml:
```toml ```toml
rocket_cors = "0.5.0" rocket_cors = "0.5.1"
``` ```
To use the latest `master` branch, for example: To use the latest `master` branch, for example:

View File

@ -328,7 +328,7 @@ mod tests {
let headers = ["foo", "bar", "baz"]; let headers = ["foo", "bar", "baz"];
let parsed_headers = not_err!(AccessControlRequestHeaders::from_str(&headers.join(", "))); let parsed_headers = not_err!(AccessControlRequestHeaders::from_str(&headers.join(", ")));
let expected_headers: HeaderFieldNamesSet = let expected_headers: HeaderFieldNamesSet =
headers.iter().map(|s| s.to_string().into()).collect(); headers.iter().map(|s| (*s).to_string().into()).collect();
let AccessControlRequestHeaders(actual_headers) = parsed_headers; let AccessControlRequestHeaders(actual_headers) = parsed_headers;
assert_eq!(actual_headers, expected_headers); assert_eq!(actual_headers, expected_headers);
} }

View File

@ -29,7 +29,7 @@ might work, but they are subject to the minimum that Rocket sets.
Add the following to Cargo.toml: Add the following to Cargo.toml:
```toml ```toml
rocket_cors = "0.5.0-beta-2" rocket_cors = "0.5.1"
``` ```
To use the latest `master` branch, for example: To use the latest `master` branch, for example:
@ -45,7 +45,7 @@ the [`CorsOptions`] struct that is described below. If you would like to disable
change your `Cargo.toml` to: change your `Cargo.toml` to:
```toml ```toml
rocket_cors = { version = "0.5.0", default-features = false } rocket_cors = { version = "0.5.1", default-features = false }
``` ```
## Usage ## Usage
@ -258,7 +258,6 @@ See the [example](https://github.com/lawliet89/rocket_cors/blob/master/examples/
while_true while_true
)] )]
#![allow( #![allow(
legacy_directory_ownership,
missing_copy_implementations, missing_copy_implementations,
missing_debug_implementations, missing_debug_implementations,
unknown_lints, unknown_lints,
@ -812,12 +811,12 @@ impl ParsedAllowedOrigins {
exact.into_iter().partition(|(_, url)| url.is_tuple()); exact.into_iter().partition(|(_, url)| url.is_tuple());
if !opaque.is_empty() { if !opaque.is_empty() {
Err(Error::OpaqueAllowedOrigin( return Err(Error::OpaqueAllowedOrigin(
opaque opaque
.into_iter() .into_iter()
.map(|(original, _)| original.to_string()) .map(|(original, _)| original.to_string())
.collect(), .collect(),
))? ));
} }
let exact = tuple.into_iter().map(|(_, url)| url).collect(); let exact = tuple.into_iter().map(|(_, url)| url).collect();
@ -907,7 +906,7 @@ pub type AllowedHeaders = AllOrSome<HashSet<HeaderFieldName>>;
impl AllowedHeaders { impl AllowedHeaders {
/// Allow some headers /// Allow some headers
pub fn some(headers: &[&str]) -> Self { pub fn some(headers: &[&str]) -> Self {
AllOrSome::Some(headers.iter().map(|s| s.to_string().into()).collect()) AllOrSome::Some(headers.iter().map(|s| (*s).to_string().into()).collect())
} }
/// Allows all headers /// Allows all headers
@ -1143,7 +1142,7 @@ impl CorsOptions {
/// Validates if any of the settings are disallowed, incorrect, or illegal /// Validates if any of the settings are disallowed, incorrect, or illegal
pub fn validate(&self) -> Result<(), Error> { pub fn validate(&self) -> Result<(), Error> {
if self.allowed_origins.is_all() && self.send_wildcard && self.allow_credentials { if self.allowed_origins.is_all() && self.send_wildcard && self.allow_credentials {
Err(Error::CredentialsWithWildcardOrigin)?; return Err(Error::CredentialsWithWildcardOrigin);
} }
Ok(()) Ok(())
@ -1296,7 +1295,7 @@ impl Response {
/// Consumes the CORS, set expose_headers to /// Consumes the CORS, set expose_headers to
/// passed headers and returns changed CORS /// passed headers and returns changed CORS
fn exposed_headers(mut self, headers: &[&str]) -> Self { fn exposed_headers(mut self, headers: &[&str]) -> Self {
self.expose_headers = headers.iter().map(|s| s.to_string().into()).collect(); self.expose_headers = headers.iter().map(|s| (*s).to_string().into()).collect();
self self
} }
@ -1317,7 +1316,7 @@ impl Response {
/// Consumes the CORS, set allow_headers to /// Consumes the CORS, set allow_headers to
/// passed headers and returns changed CORS /// passed headers and returns changed CORS
fn headers(mut self, headers: &[&str]) -> Self { fn headers(mut self, headers: &[&str]) -> Self {
self.allow_headers = headers.iter().map(|s| s.to_string().into()).collect(); self.allow_headers = headers.iter().map(|s| (*s).to_string().into()).collect();
self self
} }
@ -1680,7 +1679,7 @@ fn validate_allowed_method(
) -> Result<(), Error> { ) -> Result<(), Error> {
let &AccessControlRequestMethod(ref request_method) = method; let &AccessControlRequestMethod(ref request_method) = method;
if !allowed_methods.iter().any(|m| m == request_method) { if !allowed_methods.iter().any(|m| m == request_method) {
Err(Error::MethodNotAllowed(method.0.to_string()))? return Err(Error::MethodNotAllowed(method.0.to_string()));
} }
// TODO: Subset to route? Or just the method requested for? // TODO: Subset to route? Or just the method requested for?
@ -1698,7 +1697,7 @@ fn validate_allowed_headers(
AllOrSome::All => Ok(()), AllOrSome::All => Ok(()),
AllOrSome::Some(ref allowed_headers) => { AllOrSome::Some(ref allowed_headers) => {
if !headers.is_empty() && !headers.is_subset(allowed_headers) { if !headers.is_empty() && !headers.is_subset(allowed_headers) {
Err(Error::HeadersNotAllowed)? return Err(Error::HeadersNotAllowed);
} }
Ok(()) Ok(())
} }
@ -1991,7 +1990,7 @@ mod tests {
allow_credentials: true, allow_credentials: true,
expose_headers: ["Content-Type", "X-Custom"] expose_headers: ["Content-Type", "X-Custom"]
.iter() .iter()
.map(|s| s.to_string()) .map(|s| (*s).to_string())
.collect(), .collect(),
..Default::default() ..Default::default()
} }