Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSRV #99

Merged
merged 10 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ jobs:
matrix:
rust:
- stable
- 1.36.0
- 1.61.0
steps:
- uses: actions/checkout@v2
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Check Rust formatting
uses: actions-rs/cargo@v1
Expand All @@ -38,13 +36,22 @@ jobs:
matrix:
rust:
- stable
- 1.36.0
- 1.61.0
feature:
- ""
- actix4
- actix3
- warp
- axum
exclude:
- rust: 1.61.0
feature: actix4
- rust: 1.61.0
feature: actix3
- rust: 1.61.0
feature: warp
- rust: 1.61.0
feature: axum
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -55,10 +62,9 @@ jobs:
target
key: ${{ runner.os }}-cargo-test-${{ hashFiles('Cargo.toml') }}
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: stable
toolchain: ${{ matrix.rust }}
- name: Run test ${{ matrix.feature }}
run: |
cargo test --all-targets --features "${{ matrix.feature }}"
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "serde_qs"
repository = "https://github.com/samscott89/serde_qs"
readme = "README.md"
version = "0.13.0"
rust-version = "1.36"
rust-version = "1.61"

[dependencies]
actix-web4 = { version = "4.0", optional = true, package = "actix-web", default-features = false }
Expand All @@ -25,7 +25,7 @@ axum-framework = { package = "axum", version = "0.7", default-features = false,

[dev-dependencies]
chrono = { version = "0.4", features = ["serde"] }
csv = "1.1"
csv = "1.3"
rand = "0.8"
serde_derive = "1.0"
serde_urlencoded = "0.7"
Expand Down
17 changes: 5 additions & 12 deletions src/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ where
}
}

type ActixErrorHandler = Option<Arc<dyn Fn(QsError, &HttpRequest) -> ActixError + Send + Sync>>;

/// Query extractor configuration
///
/// ```rust
Expand Down Expand Up @@ -173,9 +175,9 @@ where
/// );
/// }
/// ```
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct QsQueryConfig {
ehandler: Option<Arc<dyn Fn(QsError, &HttpRequest) -> ActixError + Send + Sync>>,
ehandler: ActixErrorHandler,
qs_config: QsConfig,
}

Expand All @@ -201,15 +203,6 @@ impl QsQueryConfig {
}
}

impl Default for QsQueryConfig {
fn default() -> Self {
QsQueryConfig {
ehandler: None,
qs_config: QsConfig::default(),
}
}
}

#[derive(PartialEq, Eq, PartialOrd, Ord)]
/// Extract typed information from from the request's form data.
///
Expand All @@ -230,7 +223,7 @@ impl Default for QsQueryConfig {
/// }
///
/// // Use `QsForm` extractor for Form information.
/// // Content-Type: application/x-www-form-urlencoded
/// // Content-Type: application/x-www-form-urlencoded
/// // The correct request payload for this handler would be `id[]=1124&id[]=88`
/// async fn filter_users(info: QsForm<UsersFilter>) -> HttpResponse {
/// HttpResponse::Ok().body(
Expand Down
15 changes: 5 additions & 10 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl<'a, W: 'a + Write> QsSerializer<'a, W> {
write!(
self.writer,
"{}{}={}",
amp.then_some("&").unwrap_or_default(),
if amp { "&" } else { "" },
key,
percent_encode(value, QS_ENCODE_SET)
.map(replace_space)
Expand All @@ -294,16 +294,11 @@ impl<'a, W: 'a + Write> QsSerializer<'a, W> {
fn write_unit(&mut self) -> Result<()> {
let amp = !self.first.swap(false, Ordering::Relaxed);
if let Some(ref key) = self.key {
write!(
self.writer,
"{}{}=",
amp.then_some("&").unwrap_or_default(),
key,
)
.map_err(Error::from)
write!(self.writer, "{}{}=", if amp { "&" } else { "" }, key,).map_err(Error::from)
} else if amp {
write!(self.writer, "&").map_err(Error::from)
} else {
// For top level unit types
write!(self.writer, "{}", amp.then_some("&").unwrap_or_default(),).map_err(Error::from)
Ok(())
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/test_actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
S: std::str::FromStr,
{
let s = <&str as serde::Deserialize>::deserialize(deserializer)?;
S::from_str(&s).map_err(|_| D::Error::custom("could not parse string"))
S::from_str(s).map_err(|_| D::Error::custom("could not parse string"))
}

#[derive(Deserialize, Serialize, Debug, PartialEq)]
Expand Down Expand Up @@ -103,7 +103,7 @@ fn test_composite_querystring_extractor() {
assert_eq!(s.bars, vec![0, 1]);
assert_eq!(s.common.limit, 100);
assert_eq!(s.common.offset, 50);
assert_eq!(s.common.remaining, true);
assert!(s.common.remaining);
})
}

Expand Down Expand Up @@ -140,7 +140,7 @@ fn test_custom_qs_config() {
assert_eq!(s.bars, vec![3]);
assert_eq!(s.common.limit, 100);
assert_eq!(s.common.offset, 50);
assert_eq!(s.common.remaining, true);
assert!(s.common.remaining);
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn deserialize_struct() {
user_ids: vec![1, 2, 3, 4],
};

for config in vec![qs::Config::new(5, true), qs::Config::new(5, false)] {
for config in [qs::Config::new(5, true), qs::Config::new(5, false)] {
// standard parameters
let rec_params: QueryParams = config
.deserialize_str(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ where
S: std::str::FromStr,
{
let s = <&str as serde::Deserialize>::deserialize(deserializer)?;
S::from_str(&s).map_err(|_| D::Error::custom("could not parse string"))
S::from_str(s).map_err(|_| D::Error::custom("could not parse string"))
}

#[derive(Deserialize, Serialize, Debug, PartialEq)]
Expand Down Expand Up @@ -65,7 +65,7 @@ fn test_composite_querystring_extractor() {
assert_eq!(s.bars, vec![0, 1]);
assert_eq!(s.common.limit, 100);
assert_eq!(s.common.offset, 50);
assert_eq!(s.common.remaining, true);
assert!(s.common.remaining);
})
}

Expand Down Expand Up @@ -99,6 +99,6 @@ fn test_custom_qs_config() {
assert_eq!(s.bars, vec![3]);
assert_eq!(s.common.limit, 100);
assert_eq!(s.common.offset, 50);
assert_eq!(s.common.remaining, true);
assert!(s.common.remaining);
})
}
Loading