Skip to content

Commit 3a9b1fd

Browse files
authored
Fix build issues for Rocket 0.4.2 (#70)
- Fix clippy lints - Bump minimum Rust version beyond Rocket required for - `std::mem::MaybeUninit` (cf. rust-lang/rust#60445) - `alloc` crate
1 parent c75dcb2 commit 3a9b1fd

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ sudo: false
22
language: rust
33
rust:
44
- nightly
5-
# Minimum Rust set by Rocket
6-
- nightly-2018-11-25
5+
- nightly-2019-05-21 # Minimum supported
76
branches:
87
only:
98
- master

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 0.5.1 (2019-11-13)
4+
5+
There are no new features.
6+
7+
- Fix build issues with Rocket 0.4.2
8+
- Fix clippy lints with latest nightly
9+
310
## <a name="0.5.0"></a>0.5.0 (2019-05-27)
411

512
There is no change since `0.5.0-beta1`.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rocket_cors"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
license = "MIT/Apache-2.0"
55
authors = ["Yong Wen Chua <[email protected]>"]
66
description = "Cross-origin resource sharing (CORS) for Rocket.rs applications"
@@ -22,7 +22,7 @@ serialization = ["serde", "serde_derive", "unicase_serde"]
2222

2323
[dependencies]
2424
regex = "1.1"
25-
rocket = { version = "0.4.0", default-features = false }
25+
rocket = { version = "0.4.2", default-features = false }
2626
log = "0.3"
2727
unicase = "2.0"
2828
url = "1.7.2"

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Cross-origin resource sharing (CORS) for [Rocket](https://rocket.rs/) applicatio
1515

1616
If you are using Rocket 0.3, use the `0.3.0` version of this crate.
1717

18+
There is a minimum version of Rust nightly required. This is usually higher than whatever
19+
Rocket requires plus more if the dependent crates require other features.
20+
1821
### Nightly Rust
1922

2023
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.
3033
Add the following to Cargo.toml:
3134

3235
```toml
33-
rocket_cors = "0.5.0"
36+
rocket_cors = "0.5.1"
3437
```
3538

3639
To use the latest `master` branch, for example:

src/headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ mod tests {
328328
let headers = ["foo", "bar", "baz"];
329329
let parsed_headers = not_err!(AccessControlRequestHeaders::from_str(&headers.join(", ")));
330330
let expected_headers: HeaderFieldNamesSet =
331-
headers.iter().map(|s| s.to_string().into()).collect();
331+
headers.iter().map(|s| (*s).to_string().into()).collect();
332332
let AccessControlRequestHeaders(actual_headers) = parsed_headers;
333333
assert_eq!(actual_headers, expected_headers);
334334
}

src/lib.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ might work, but they are subject to the minimum that Rocket sets.
2929
Add the following to Cargo.toml:
3030
3131
```toml
32-
rocket_cors = "0.5.0-beta-2"
32+
rocket_cors = "0.5.1"
3333
```
3434
3535
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
4545
change your `Cargo.toml` to:
4646
4747
```toml
48-
rocket_cors = { version = "0.5.0", default-features = false }
48+
rocket_cors = { version = "0.5.1", default-features = false }
4949
```
5050
5151
## Usage
@@ -258,7 +258,6 @@ See the [example](https://github.com/lawliet89/rocket_cors/blob/master/examples/
258258
while_true
259259
)]
260260
#![allow(
261-
legacy_directory_ownership,
262261
missing_copy_implementations,
263262
missing_debug_implementations,
264263
unknown_lints,
@@ -812,12 +811,12 @@ impl ParsedAllowedOrigins {
812811
exact.into_iter().partition(|(_, url)| url.is_tuple());
813812

814813
if !opaque.is_empty() {
815-
Err(Error::OpaqueAllowedOrigin(
814+
return Err(Error::OpaqueAllowedOrigin(
816815
opaque
817816
.into_iter()
818817
.map(|(original, _)| original.to_string())
819818
.collect(),
820-
))?
819+
));
821820
}
822821

823822
let exact = tuple.into_iter().map(|(_, url)| url).collect();
@@ -907,7 +906,7 @@ pub type AllowedHeaders = AllOrSome<HashSet<HeaderFieldName>>;
907906
impl AllowedHeaders {
908907
/// Allow some headers
909908
pub fn some(headers: &[&str]) -> Self {
910-
AllOrSome::Some(headers.iter().map(|s| s.to_string().into()).collect())
909+
AllOrSome::Some(headers.iter().map(|s| (*s).to_string().into()).collect())
911910
}
912911

913912
/// Allows all headers
@@ -1143,7 +1142,7 @@ impl CorsOptions {
11431142
/// Validates if any of the settings are disallowed, incorrect, or illegal
11441143
pub fn validate(&self) -> Result<(), Error> {
11451144
if self.allowed_origins.is_all() && self.send_wildcard && self.allow_credentials {
1146-
Err(Error::CredentialsWithWildcardOrigin)?;
1145+
return Err(Error::CredentialsWithWildcardOrigin);
11471146
}
11481147

11491148
Ok(())
@@ -1296,7 +1295,7 @@ impl Response {
12961295
/// Consumes the CORS, set expose_headers to
12971296
/// passed headers and returns changed CORS
12981297
fn exposed_headers(mut self, headers: &[&str]) -> Self {
1299-
self.expose_headers = headers.iter().map(|s| s.to_string().into()).collect();
1298+
self.expose_headers = headers.iter().map(|s| (*s).to_string().into()).collect();
13001299
self
13011300
}
13021301

@@ -1317,7 +1316,7 @@ impl Response {
13171316
/// Consumes the CORS, set allow_headers to
13181317
/// passed headers and returns changed CORS
13191318
fn headers(mut self, headers: &[&str]) -> Self {
1320-
self.allow_headers = headers.iter().map(|s| s.to_string().into()).collect();
1319+
self.allow_headers = headers.iter().map(|s| (*s).to_string().into()).collect();
13211320
self
13221321
}
13231322

@@ -1680,7 +1679,7 @@ fn validate_allowed_method(
16801679
) -> Result<(), Error> {
16811680
let &AccessControlRequestMethod(ref request_method) = method;
16821681
if !allowed_methods.iter().any(|m| m == request_method) {
1683-
Err(Error::MethodNotAllowed(method.0.to_string()))?
1682+
return Err(Error::MethodNotAllowed(method.0.to_string()));
16841683
}
16851684

16861685
// TODO: Subset to route? Or just the method requested for?
@@ -1698,7 +1697,7 @@ fn validate_allowed_headers(
16981697
AllOrSome::All => Ok(()),
16991698
AllOrSome::Some(ref allowed_headers) => {
17001699
if !headers.is_empty() && !headers.is_subset(allowed_headers) {
1701-
Err(Error::HeadersNotAllowed)?
1700+
return Err(Error::HeadersNotAllowed);
17021701
}
17031702
Ok(())
17041703
}
@@ -1991,7 +1990,7 @@ mod tests {
19911990
allow_credentials: true,
19921991
expose_headers: ["Content-Type", "X-Custom"]
19931992
.iter()
1994-
.map(|s| s.to_string())
1993+
.map(|s| (*s).to_string())
19951994
.collect(),
19961995
..Default::default()
19971996
}

0 commit comments

Comments
 (0)