diff options
author | Sam Scott <sam@osohq.com> | 2024-04-07 15:23:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-07 15:23:28 -0500 |
commit | 2bb118fce16f2d5a1a85fce96d228acc23df827e (patch) | |
tree | 56ca89d79ba4d959f365004df5ab134adf79ac68 /src | |
parent | c6e5914a31e0d602695a3ea601f6976a1ab07d0e (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/actix.rs | 17 | ||||
-rw-r--r-- | src/ser.rs | 15 |
2 files changed, 10 insertions, 22 deletions
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<Arc<dyn Fn(QsError, &HttpRequest) -> ActixError + Send + Sync>>; + /// Query extractor configuration /// /// ```rust @@ -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, } @@ -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<UsersFilter>) -> HttpResponse { /// HttpResponse::Ok().body( @@ -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(()) } } |