[fractal] fractal-matrix-api: More idiomatic if/else assignments
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] fractal-matrix-api: More idiomatic if/else assignments
- Date: Sun, 23 Dec 2018 11:07:15 +0000 (UTC)
commit b93f1e4420406d649be61d767fc533620b1d279f
Author: Zeeshan Ali <zeenix collabora co uk>
Date: Wed Dec 12 23:05:44 2018 +0100
fractal-matrix-api: More idiomatic if/else assignments
This fixes these errors from clippy:
```
error: `if _ { .. } else { .. }` is an expression
--> fractal-matrix-api/src/util.rs:525:5
|
525 | / let path: String;
526 | |
527 | | if thumb {
528 | | params.push(("width", format!("{}", w)));
... |
533 | | path = format!("download/{}/{}", server, media);
534 | | }
| |_____^ help: it is more idiomatic to write: `let path = if thumb { ..; $ crate :: fmt :: format (
format_args ! ( $ ( $ arg ) * ) ) } else { $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) ) };`
|
= note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
= help: for further information visit
https://rust-lang-nursery.github.io/rust-clippy/master/index.html#useless_let_if_seq
```
Related: #370
fractal-matrix-api/src/backend/register.rs | 13 ++++++-------
fractal-matrix-api/src/util.rs | 18 ++++++++----------
2 files changed, 14 insertions(+), 17 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/register.rs b/fractal-matrix-api/src/backend/register.rs
index d1fa20d..95bd71a 100644
--- a/fractal-matrix-api/src/backend/register.rs
+++ b/fractal-matrix-api/src/backend/register.rs
@@ -43,11 +43,10 @@ fn build_login_attrs(user: &str, password: &str) -> Result<JsonValue, Error> {
let emailre = Regex::new(
r"^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])+@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$",
)?;
- let attrs;
// Email
- if emailre.is_match(&user) {
- attrs = json!({
+ let attrs = if emailre.is_match(&user) {
+ json!({
"type": "m.login.password",
"password": password,
"initial_device_display_name": "Fractal",
@@ -58,15 +57,15 @@ fn build_login_attrs(user: &str, password: &str) -> Result<JsonValue, Error> {
"medium": "email",
"address": user,
}
- });
+ })
} else {
- attrs = json!({
+ json!({
"type": "m.login.password",
"initial_device_display_name": "Fractal",
"user": user,
"password": password
- });
- }
+ })
+ };
Ok(attrs)
}
diff --git a/fractal-matrix-api/src/util.rs b/fractal-matrix-api/src/util.rs
index 7ccfaa5..8bb25cb 100644
--- a/fractal-matrix-api/src/util.rs
+++ b/fractal-matrix-api/src/util.rs
@@ -513,16 +513,15 @@ pub fn resolve_media_url(base: &Url, url: &str, thumb: bool, w: i32, h: i32) ->
let media = String::from(&caps["media"]);
let mut params: Vec<(&str, String)> = vec![];
- let path: String;
- if thumb {
+ let path = if thumb {
params.push(("width", format!("{}", w)));
params.push(("height", format!("{}", h)));
params.push(("method", String::from("scale")));
- path = format!("thumbnail/{}/{}", server, media);
+ format!("thumbnail/{}/{}", server, media)
} else {
- path = format!("download/{}/{}", server, media);
- }
+ format!("download/{}/{}", server, media)
+ };
media_url(base, &path, ¶ms)
}
@@ -541,16 +540,15 @@ pub fn dw_media(
let media = String::from(&caps["media"]);
let mut params: Vec<(&str, String)> = vec![];
- let path: String;
- if thumb {
+ let path = if thumb {
params.push(("width", format!("{}", w)));
params.push(("height", format!("{}", h)));
params.push(("method", String::from("crop")));
- path = format!("thumbnail/{}/{}", server, media);
+ format!("thumbnail/{}/{}", server, media)
} else {
- path = format!("download/{}/{}", server, media);
- }
+ format!("download/{}/{}", server, media)
+ };
let url = media_url(base, &path, ¶ms)?;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]