From 2bb118fce16f2d5a1a85fce96d228acc23df827e Mon Sep 17 00:00:00 2001 From: Sam Scott Date: Sun, 7 Apr 2024 15:23:28 -0500 Subject: Fix MSRV (#99) * Remove `then_some` to stay compatible with earlier versions of Rust * Fix CI builds to build on old versions of Rust * Trying 1.61 --- src/actix.rs | 17 +++++------------ src/ser.rs | 15 +++++---------- 2 files changed, 10 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/actix.rs b/src/actix.rs index 176ce7d..02e9ae8 100644 --- a/src/actix.rs +++ b/src/actix.rs @@ -134,6 +134,8 @@ where } } +type ActixErrorHandler = Option ActixError + Send + Sync>>; + /// Query extractor configuration /// /// ```rust @@ -173,9 +175,9 @@ where /// ); /// } /// ``` -#[derive(Clone)] +#[derive(Clone, Default)] pub struct QsQueryConfig { - ehandler: Option ActixError + Send + Sync>>, + ehandler: ActixErrorHandler, qs_config: QsConfig, } @@ -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. /// @@ -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) -> HttpResponse { /// HttpResponse::Ok().body( diff --git a/src/ser.rs b/src/ser.rs index 607fa0d..5198d71 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -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) @@ -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(()) } } -- cgit v1.2.3