Optimize type casting

This commit is contained in:
spikecodes 2021-03-08 18:49:06 -08:00
parent 213babb057
commit bf783c2f3a
No known key found for this signature in database
GPG key ID: 004CECFF9B463BCB
8 changed files with 32 additions and 28 deletions

View file

@ -1,3 +1,7 @@
// Global specifiers
#![forbid(unsafe_code)]
#![warn(clippy::pedantic, clippy::all)]
// Reference local files
mod post;
mod proxy;
@ -48,10 +52,10 @@ impl<State: Clone + Send + Sync + 'static> Middleware<State> for NormalizePath {
if path.ends_with('/') {
Ok(next.run(request).await)
} else {
let normalized = if query != "" {
format!("{}/?{}", path.replace("//", "/"), query)
} else {
let normalized = if query.is_empty() {
format!("{}/", path.replace("//", "/"))
} else {
format!("{}/?{}", path.replace("//", "/"), query)
};
Ok(redirect(normalized))
}